Re: Implementation of sFTP using Perl

2014-04-07 Thread Wernher Eksteen
I preffer to use Net::OpenSSH (
http://search.cpan.org/~salva/Net-OpenSSH-0.60/lib/Net/OpenSSH.pm)

This is an exceptional Perl module on most things SSH related, not limited
to just sFTP which allows the use of various other SSH calls from the same
module without the need to use other modules to fulfill other requirements.
For me this is the swisarmy knife for Perl on SSH related things, it's
feature rich and simple to use and can do things in parallel.


On Thu, Jan 12, 2012 at 7:16 PM, Wagner, David --- Sr Programmer Analyst
--- CFS  wrote:

>
> I need to change from FTP to sFTP and want to use a Perl
> implementation verses using sFTP application bound within Perl scripts.
> I will be running from Linux and pulling data either from MVS or
> Windows box or servers.
>
> Uncertain how to proceed? Will attempt to use AS Linux Perl
> version.
>
> Thoughts???
>
> Thanks
>
> Wags ;)
> David R. Wagner
> Senior Programmer Analyst
> FedEx Services
> 1.719.484.2097 Tel
> 1.719.484.2419 Fax
> 1.408.623.5963 Cell
> http://Fedex.com/us
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: Reading a config file and exporting it updated with the new/changes values in the same format.

2014-03-03 Thread Wernher Eksteen
So, based on the config examples I gave above, the Perl script I'm writing
will do the following:

1. Read the existing config file and determine the following:
- How many hosts are there and what are their names.
- What are the contactgroups and tag_criticality values for each host ie:
"prod" or "test"

2. Get the input values for new hostnames that will be added to the config
along with it's contactgroups and tag_criticality values.

3. Add the new hostnames along with it's contactgroups and tag_criticality
values passed as input values to the script.

4. The script will then add the new hostnames and their values to the
existing config file, keeping current hostname entries and their values in
place.

5. The script will then also have the ability to do the opposite by
removing hostnames and their values from the config file, keeping other
hostname entries and their values intact.

Regards,
Wernher


On Tue, Mar 4, 2014 at 5:18 AM, Wernher Eksteen  wrote:

> Hi Jim,
>
> The format of the config file is like this:
>
> *Config file example1:* For one host in this case named hostname1
> belonging to 4 contactgroups (group1 to group4),
>
> < begin config file example 1 >
>
>
> host_contactgroups += [
> ( 'group1', ['hostname1'] ),
> ( 'group2', ['hostname1'] ),
> ( 'group3', ['hostname1'] ),
> ( 'group4', ['hostname1'] ),
> ]
>
> all_hosts += [
>   "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
> ]
>
> #  Explicit IP addresses
> ipaddresses.update({'hostname1': u'hostname1.domain.com'})
>
> # Settings for alias
> extra_host_conf.setdefault('alias', []).extend((u'hostname1.domain.com',
> ['hostname1'])])
>
>
> # Host attributes
> host_attributes.update(
> {'hostname1': {'alias': u'hostname1.domain.com',
>   'contactgroups': (True, ['group1', 'group2', 'group3',
> 'group4']),
>   'ipaddress': u'hostname1.domain.com',
>   'tag_agent': 'cmk-agent',
>   'tag_criticality': 'prod',
>   'tag_networking': 'lan'}})
>
> < end config file example 1 >
>
> *Config file example 2:* For three host in this case, hostname1,
> hostname2 and hostname3, with hostname1 belonging to contactgroups "group1
> to group4",  hostname2 belonging to contactgroups "group3 and group4", and
> hostname3 belonging to contactgroups "group3" only.
>
> < begin config file example 2 >
>
> host_contactgroups += [
> ( 'group1', ['hostname1'] ),
> ( 'group2', ['hostname1'] ),
> ( 'group3', ['hostname1'] ),
> ( 'group4', ['hostname1'] ),
> ]
>
> host_contactgroups += [
> ( 'group3', ['hostname2'] ),
> ( 'group4', ['hostname2'] ),
> ]
>
> host_contactgroups += [
> ( 'group3', ['hostname3'] ),
> ]
>
> all_hosts += [
>   "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
>   "hostname2|test|cmk-agent|lan|tcp|wato|/" + FOLDER_PATH + "/",
>   "hostname3|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
> ]
>
> #  Explicit IP addresses
> ipaddresses.update({'hostname1': u'hostname1.domain.com',
>  'hostname2': u'hostname2.domain.com',
>  'hostname3': u'hostname3.domain.com'})
>
> # Settings for alias
> extra_host_conf.setdefault('alias', []).extend(
>   [(u'hostname3.domain.com', ['hostname3']),
>  (u'hostname2.domain.com', ['hostname2']),
>  (u'hostname1.domain.com', ['hostname1'])])
>
> # Host attributes
> host_attributes.update(
> {'hostname1': {'alias': u'hostname1.domain.com',
>   'contactgroups': (True, ['group1', 'group2', 'group3',
> 'group4']),
>   'ipaddress': u'hostname1.domain.com',
>   'tag_agent': 'cmk-agent',
>   'tag_criticality': 'prod',
>   'tag_networking': 'lan'},
>  'hostname2': {'alias': u'hostname2.domain.com',
>  

Re: Reading a config file and exporting it updated with the new/changes values in the same format.

2014-03-03 Thread Wernher Eksteen
Hi Jim,

The format of the config file is like this:

*Config file example1:* For one host in this case named hostname1 belonging
to 4 contactgroups (group1 to group4),

< begin config file example 1 >

host_contactgroups += [
( 'group1', ['hostname1'] ),
( 'group2', ['hostname1'] ),
( 'group3', ['hostname1'] ),
( 'group4', ['hostname1'] ),
]

all_hosts += [
  "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
]

#  Explicit IP addresses
ipaddresses.update({'hostname1': u'hostname1.domain.com'})

# Settings for alias
extra_host_conf.setdefault('alias', []).extend((u'hostname1.domain.com',
['hostname1'])])

# Host attributes
host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
  'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
  'ipaddress': u'hostname1.domain.com',
  'tag_agent': 'cmk-agent',
  'tag_criticality': 'prod',
  'tag_networking': 'lan'}})

< end config file example 1 >

*Config file example 2:* For three host in this case, hostname1, hostname2
and hostname3, with hostname1 belonging to contactgroups "group1 to
group4",  hostname2 belonging to contactgroups "group3 and group4", and
hostname3 belonging to contactgroups "group3" only.

< begin config file example 2 >

host_contactgroups += [
( 'group1', ['hostname1'] ),
( 'group2', ['hostname1'] ),
( 'group3', ['hostname1'] ),
( 'group4', ['hostname1'] ),
]

host_contactgroups += [
( 'group3', ['hostname2'] ),
( 'group4', ['hostname2'] ),
]

host_contactgroups += [
( 'group3', ['hostname3'] ),
]

all_hosts += [
  "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname2|test|cmk-agent|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname3|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
]

#  Explicit IP addresses
ipaddresses.update({'hostname1': u'hostname1.domain.com',
 'hostname2': u'hostname2.domain.com',
 'hostname3': u'hostname3.domain.com'})

# Settings for alias
extra_host_conf.setdefault('alias', []).extend(
  [(u'hostname3.domain.com', ['hostname3']),
 (u'hostname2.domain.com', ['hostname2']),
 (u'hostname1.domain.com', ['hostname1'])])

# Host attributes
host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
  'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
  'ipaddress': u'hostname1.domain.com',
  'tag_agent': 'cmk-agent',
  'tag_criticality': 'prod',
  'tag_networking': 'lan'},
 'hostname2': {'alias': u'hostname2.domain.com',
 'contactgroups': (True, ['group3', 'group4']),
 'ipaddress': u'hostname2.domain.com',
 'tag_agent': 'cmk-agent',
 'tag_criticality': 'test',
 'tag_networking': 'lan'},
 'hostname3': {'alias': u'hostname3.domain.com',
 'contactgroups': (True, ['group3']),
 'ipaddress': u'hostname3.domain.com',
 'tag_agent': 'cmk-agent',
 'tag_criticality': 'prod',
 'tag_networking': 'lan'}})

< end config file example 2 -------->

Final note: Notice the lines containing FOLDER_PATH in the *all_hosts
+=*section in config file example 2:

  "hostname1|cmk-agent*|prod*|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname2|*test*|cmk-agent|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname3|cmk-agent|*prod*|lan|tcp|wato|/" + FOLDER_PATH + "/",

Where hostname1 and hostname 3 contains "prod" and hostname 2 contains
"test" which indicates that hostname 2 is a test server whilst the others
are production hosts.

The very last section under # Host attributes section: *host_attributes.update
*is then basically build up from the infor

Re: Reading a config file and exporting it updated with the new/changes values in the same format.

2014-03-03 Thread Wernher Eksteen
Hi Shlomi,

Thank you for the pointers. I do want to learn Python as well when I get a
chance. This "framework" I'm writing now will automate things to a great
extend eventually freeing up loads of my daily operations time so I can
focus on more interesting things.

I'm really not expecting the code to be written for me, mere pointers as
you did (with some examples would be a plus) is all that's needed for me to
look into that and take it further.

The example here: http://perl-begin.org/uses/text-parsing/ already helps
quite a bit.

Regards,
Wernher


On Mon, Mar 3, 2014 at 12:33 PM, Shlomi Fish  wrote:

> Hello Wernher,
>
> On Sun, 2 Mar 2014 21:42:00 +0200
> Wernher Eksteen  wrote:
>
> > Hi Everyone,
> >
> > I need your help with this one please.
> >
> > I have a config file that is written/updated with a Python based web
> front
> > end tool. I would like to add/remove hosts to/from this config file using
> > Perl.
> >
> > The idea I have is for Perl to read this config file, and instead of
> > adding/replcing values to the original config file, to re-write the
> config
> > file with the
> > latest hostname that was added or removed to a new config file in the
> same
> > format so that the Python based web tool can read it.
> >
> > This exceeds my knowledge of Perl at the moment and hope I can learn the
> > ways from the Perl Masters :-)
>
> Hi, I'm going to share several possible approaches for writing such a code
> which you can study and implement on your own. What I'm not going to do is
> write your code for you - for me to do that, you'll need to hire me and pay
> me for my time.
>
> In any case, here are some approaches you can take:
>
> 1. Write the whole thing in Python instead of Perl.
>
> 2. Call to a Python program from the perl program using a different
> process.
>
> 3. Use Inline::Python ( https://metacpan.org/release/Inline-Python ) to
> embed
> Python code inside Perl.
>
> 4. Parse the file using the parsing techniques described in
> http://perl-begin.org/uses/text-parsing/ - including the description of
> parser
> generators here -
> http://perl-begin.org/uses/text-parsing/#parser-generators
> (*Note*: perl-begin.org is a site I originated and maintain), modify its
> intermediate representation and output it again. Note that parsing can be
> quite
> errorprone.
>
> Regards,
>
> Shlomi Fish
>
> --
> -
> Shlomi Fish   http://www.shlomifish.org/
> First stop for Perl beginners - http://perl-begin.org/
>
> If you have the same ideas as everybody else, but have them one week
> earlier
> than everyone else -- then you will be hailed as a visionary. But if you
> have
> them five years earlier, you will be named a lunatic. ( Barry Jones )
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply .
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Reading a config file and exporting it updated with the new/changes values in the same format.

2014-03-02 Thread Wernher Eksteen
Hi Everyone,

I need your help with this one please.

I have a config file that is written/updated with a Python based web front
end tool. I would like to add/remove hosts to/from this config file using
Perl.

The idea I have is for Perl to read this config file, and instead of
adding/replcing values to the original config file, to re-write the config
file with the
latest hostname that was added or removed to a new config file in the same
format so that the Python based web tool can read it.

This exceeds my knowledge of Perl at the moment and hope I can learn the
ways from the Perl Masters :-)

The basic explanation of the different sections for each that exist in the
config file:

*Every hostname belongs to their own contact groups with a section:
host_contactgroups*

host_contactgroups += [ ('group1', ['hostname1']), ]

*Every host must belong to the section with other hosts:all_hosts*

all_hosts += [ "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH
+ "/", ]

*Every host must belong to the section shared with other hosts:
ipaddresses.update*

ipaddresses.update({'hostname1': u'hostname1.domain.com'})

*Every host must belong to the section shared with other hosts:
extra_host_conf.setdefault*

 extra_host_conf.setdefault('alias', []).extend( (u'hostname1.domain.com',
['hostname1'])])

*Finally every host must have it's own section: host_attributes.update*

host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
  'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
  'ipaddress': u'hostname1.domain.com',
  'tag_agent': 'cmk-agent',
  'tag_criticality': 'prod',
  'tag_networking': 'lan'},

*The actual config file looks like this:*

host_contactgroups += [
( 'group1', ['hostname1'] ),
( 'group2', ['hostname1'] ),
( 'group3', ['hostname1'] ),
( 'group4', ['hostname1'] ),
]

host_contactgroups += [
( 'group3', ['hostname2'] ),
( 'group4', ['hostname2'] ),
]

host_contactgroups += [
( 'group3', ['hostname3'] ),
]

all_hosts += [
  "hostname1|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname2|test|cmk-agent|lan|tcp|wato|/" + FOLDER_PATH + "/",
  "hostname3|cmk-agent|prod|lan|tcp|wato|/" + FOLDER_PATH + "/",
]

#  Explicit IP addresses
ipaddresses.update({'hostname1': u'hostname1.domain.com',
 'hostname2': u'hostname2.domain.com',
 'hostname3': u'hostname3.domain.com'})

# Settings for alias
extra_host_conf.setdefault('alias', []).extend(
  [(u'hostname3.domain.com', ['hostname3']),
 (u'hostname2.domain.com', ['hostname2']),
 (u'hostname1.domain.com', ['hostname1'])])

# Host attributes
host_attributes.update(
{'hostname1': {'alias': u'hostname1.domain.com',
  'contactgroups': (True, ['group1', 'group2', 'group3',
'group4']),
  'ipaddress': u'hostname1.domain.com',
  'tag_agent': 'cmk-agent',
  'tag_criticality': 'prod',
  'tag_networking': 'lan'},
 'hostname2': {'alias': u'hostname2.domain.com',
 'contactgroups': (True, ['group3', 'group4']),
 'ipaddress': u'hostname2.domain.com',
 'tag_agent': 'cmk-agent',
 'tag_criticality': 'test',
 'tag_networking': 'lan'},
 'hostname3': {'alias': u'hostname3.domain.com',
 'contactgroups': (True, ['group3']),
 'ipaddress': u'hostname3.domain.com',
 'tag_agent': 'cmk-agent',
 'tag_criticality': 'prod',
 'tag_networking': 'lan'}})

Many thanks,
Wernher


Re: regex to get version from file name

2014-02-23 Thread Wernher Eksteen
Great thank you!


On Fri, Feb 21, 2014 at 6:02 PM, Jim Gibson  wrote:

>
> On Feb 21, 2014, at 6:21 AM, Wernher Eksteen  wrote:
>
> > Hi all,
> >
> > From the below file names I only need the version number 1.2.4 without
> explicitly specifying it.
> >
> >  check_mk-1.2.4.tar.gz
> >  check_mk-agent-1.2.4-1.noarch.rpm
> >  check_mk-agent-logwatch-1.2.4-1.noarch.rpm
> >  check_mk-agent-oracle-1.2.4-1.noarch.rpm
> >  mk-livestatus-1.2.4.tar.gz
> >  mkeventd-1.2.4.tar.gz
> >
> > What regex can I use to obtain only the string value 1.2.4 from the file
> names (or whatever future versions based on the 3 numbers separated by 3
> dots, [0-9].[0-9].[0-9]?
>
> Here's one that will do any number of digits, provided they are preceded
> by a hyphen and followed by a hyphen or period (like all of your samples):
>
>   /-([\d.]+)[.-]/
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: regex to get version from file name

2014-02-23 Thread Wernher Eksteen
Thanks, this also worked for me...

foreach my $i (@fileList) {
push @versions, $i =~ m/\b(\d+\.\d+\.\d+)\b/g;
}

my %seen;
my @unique = grep { ! $seen{$_}++ } @versions;



On Sun, Feb 23, 2014 at 4:27 PM, Jim Gibson  wrote:

>
> On Feb 23, 2014, at 5:10 AM, Wernher Eksteen  wrote:
>
> > Hi,
> >
> > Thanks, but how do I assign the value found by the regex to a variable
> so that the "1.2.4" from 6 file names in the array @fileList are print only
> once, and if there are other versions found say 1.2.5 and 1.2.6 to print
> the unique values from all.
> >
> >
> > From that I want to get the value 1.2.4 and assign it to a variable, if
> there are more than one value such as 1.2.5 and 1.2.6 as well, it should
> print them too, but only the unique values.
> >
> > My attempt shown below to print only the value 1.2.4 is as follow, but
> it prints out "1.2.41.2.41.2.41.2.41.2.41.2.4" next to each other, if I
> pass a newline to $i such as "$i\n" it then prints "11" ?
> >
> > foreach my $i (@fileList) {
> > print $i =~  /\b(\d+\.\d+\.\d+)\b/;
> > }
>
> The parentheses in the above regular expression cause the matched
> substrings to be assigned to $1. If you wish to print those values, print
> $1 or assign the value of $1 to another variable and print it:
>
>   if( $i =~  /\b(\d+\.\d+\.\d+)\b/ ) {
> print "$1\n";
>   }
>
> If you wish to find all of the unique values of what is captured, use the
> values as keys in a hash and print the keys after all the lines have been
> processed (untested):
>
> my %unique;
> foreach my $i (@fileList) {
>   if( $i =~  /\b(\d+\.\d+\.\d+)\b/ ) {
> $unique{$1}++;
> }
> for my $number ( sort keys %unique ) {
>   print "Version $number had $unique{$number} files\n";
> }
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Re: regex to get version from file name

2014-02-23 Thread Wernher Eksteen
Thanks, I've changed it to use LWP.

I'm not sure how to download the actual file with LWP, so I've tried
File::Fetch which works, but it doesn't show download progress/status etc,
just hanging blank until the download completes. Any pointers on getting
download status/progress details?

foreach my $i (@fileList2) {
  my $file = "$url/$i" if $i =~ m/$getMenuItem/g;
  chomp($file);
  my $ff = File::Fetch->new(uri => "$file");
  my $where = $ff->fetch() or die $ff->error;
}

Thanks,
Wernher



On Sun, Feb 23, 2014 at 4:35 PM, shawn wilson  wrote:

> Use LWP to get web data - not lynx and the like unless you can't help it.
> I prefer using Web::Scraper to parse html but either way it's probably best
> not to use a regex (see SO and similar for discussions on the like).
>
> On Feb 23, 2014 8:13 AM, "Wernher Eksteen"  wrote:
> >
> > Hi,
> >
> > Thanks, but how do I assign the value found by the regex to a variable
> so that the "1.2.4" from 6 file names in the array @fileList are print only
> once, and if there are other versions found say 1.2.5 and 1.2.6 to print
> the unique values from all.
> >
> > This is my script thus far. The aim of this script is to connect to the
> site, remove all html tags and obtain only the file names I need.
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > # initiating package names to be used later
> > my @getList;
> > my @fileList;
> >
> > # get files using lynx and parse through it
> > my $url = "http://mathias-kettner.com/download";;
> > open my $in, "lynx -dump $url |" or die $!;
> >
> > # get the bits we need and push it to an array to further filter what we
> need
> > while(<$in>){
> >  chomp;
> >   if( /\[(\d+)\](.+)/ ){
> >next if $1 == 1;
> > push @getList, "$2\n";
> >  }
> > }
> >
> > # filter only the files we need into final array
> > foreach my $i (@getList) {
> >   my @list = split /\s+/, $i;
> >   push @fileList, "$list[0]\n", if $i =~ /rpm|tar/ && $i !~ /[0-9][a-z]/;
> > }
> >
> > # print the list
> > print "\nList of files to be retrieved from $url:\n\n @fileList\n";
> >
> > The output is then:
> >
> > List of files to be retrieved from http://mathias-kettner.com/download:
> >
> >
> >  check_mk-1.2.4.tar.gz
> >  check_mk-agent-1.2.4-1.noarch.rpm
> >  check_mk-agent-logwatch-1.2.4-1.noarch.rpm
> >  check_mk-agent-oracle-1.2.4-1.noarch.rpm
> >  mk-livestatus-1.2.4.tar.gz
> >  mkeventd-1.2.4.tar.gz
> >
> > From that I want to get the value 1.2.4 and assign it to a variable, if
> there are more than one value such as 1.2.5 and 1.2.6 as well, it should
> print them too, but only the unique values.
> >
> > My attempt shown below to print only the value 1.2.4 is as follow, but
> it prints out "1.2.41.2.41.2.41.2.41.2.41.2.4" next to each other, if I
> pass a newline to $i such as "$i\n" it then prints "11" ?
> >
> > foreach my $i (@fileList) {
> > print $i =~  /\b(\d+\.\d+\.\d+)\b/;
> > }
> >
>
> The 1s are all of the returns of true (or one match). You want to print
> "$i\n" if (foo)
>


Re: regex to get version from file name

2014-02-23 Thread Wernher Eksteen
Hi,

Thanks, but how do I assign the value found by the regex to a variable so
that the "1.2.4" from 6 file names in the array @fileList are print only
once, and if there are other versions found say 1.2.5 and 1.2.6 to print
the unique values from all.

This is my script thus far. The aim of this script is to connect to the
site, remove all html tags and obtain only the file names I need.

#!/usr/bin/perl

use strict;
use warnings;


*# initiating package names to be used later*my @getList;
my @fileList;


*# get files using lynx and parse through it*my $url = "
http://mathias-kettner.com/download";;
open my $in, "lynx -dump $url |" or die $!;


*# get the bits we need and push it to an array to further filter what we
need*while(<$in>){
 chomp;
  if( /\[(\d+)\](.+)/ ){
   next if $1 == 1;
push @getList, "$2\n";
 }
}

*# filter only the files we need into final array*
foreach my $i (@getList) {
  my @list = split /\s+/, $i;
  push @fileList, "$list[0]\n", if $i =~ /rpm|tar/ && $i !~ /[0-9][a-z]/;
}


*# print the list*
print "\nList of files to be retrieved from $url:\n\n @fileList\n";


*The output is then:*
List of files to be retrieved from http://mathias-kettner.com/download:

 check_mk-1.2.4.tar.gz
 check_mk-agent-1.2.4-1.noarch.rpm
 check_mk-agent-logwatch-1.2.4-1.noarch.rpm
 check_mk-agent-oracle-1.2.4-1.noarch.rpm
 mk-livestatus-1.2.4.tar.gz
 mkeventd-1.2.4.tar.gz

>From that I want to get the value 1.2.4 and assign it to a variable, if
there are more than one value such as 1.2.5 and 1.2.6 as well, it should
print them too, but only the unique values.

My attempt shown below to print only the value 1.2.4 is as follow, but it
prints out "1.2.41.2.41.2.41.2.41.2.41.2.4" next to each other, if I pass a
newline to $i such as "$i\n" it then prints "11" ?

foreach my $i (@fileList) {
print $i =~  /\b(\d+\.\d+\.\d+)\b/;
}

Thank you,
Wernher

On Fri, Feb 21, 2014 at 4:27 PM, Shawn H Corey wrote:

> On Fri, 21 Feb 2014 16:21:57 +0200
> Wernher Eksteen  wrote:
>
> > Hi all,
> >
> > From the below file names I only need the version number 1.2.4 without
> > explicitly specifying it.
> >
> >  check_mk-1.2.4.tar.gz
> >  check_mk-agent-1.2.4-1.noarch.rpm
> >  check_mk-agent-logwatch-1.2.4-1.noarch.rpm
> >  check_mk-agent-oracle-1.2.4-1.noarch.rpm
> >  mk-livestatus-1.2.4.tar.gz
> >  mkeventd-1.2.4.tar.gz
> >
> > What regex can I use to obtain only the string value 1.2.4 from the
> > file names (or whatever future versions based on the 3 numbers
> > separated by 3 dots, [0-9].[0-9].[0-9]?
> >
> > Thanks!
> > Wernher
>
> /\b(\d+\.\d+\.\d+)\b/
>
>
> --
> Don't stop where the ink does.
> Shawn
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


regex to get version from file name

2014-02-21 Thread Wernher Eksteen
Hi all,

>From the below file names I only need the version number 1.2.4 without
explicitly specifying it.

 check_mk-1.2.4.tar.gz
 check_mk-agent-1.2.4-1.noarch.rpm
 check_mk-agent-logwatch-1.2.4-1.noarch.rpm
 check_mk-agent-oracle-1.2.4-1.noarch.rpm
 mk-livestatus-1.2.4.tar.gz
 mkeventd-1.2.4.tar.gz

What regex can I use to obtain only the string value 1.2.4 from the file
names (or whatever future versions based on the 3 numbers separated by 3
dots, [0-9].[0-9].[0-9]?

Thanks!
Wernher


Comparing two arrays

2012-06-06 Thread Wernher Eksteen
Hi,

I have two arrays that I need to compare, and then print the differences:

@array1 contains this:

/dev/sdmt1 /c4devpr64
/dev/sdmq1 /c4devpr66
/dev/sdmp1 /c4devpr67
/dev/sdml1 /c4devpr69

@array2 contains this:

/dev/sdmt1 /c4devpr64
/dev/sdms1 /c4devpr65
/dev/sdmn1 /c4devpr68
/dev/sdml1 /c4devpr69

The comparison should then pick up the differences and print them out:

array1 does not contain the following, but array2 does:
/dev/sdms1 /c4devpr65
/dev/sdmn1 /c4devpr68

array2 does not contain the following, but array1 does:
/dev/sdmq1 /c4devpr66
/dev/sdmp1 /c4devpr67

Regards,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I install a perl module without a root authority?

2011-08-16 Thread Wernher Eksteen
If you can justify the need for it and the importance thereof, surely your
Linux/Unix Admin can install it
for you or provide you with the necessary sudo access so you can do it
yourself. That probably
depends on various factors, ie if that's a production system, if change
control needs to take place,
if the security policy allows it etc etc...

Otherwise you will need to localise things to your account using local:lib

Good luck

On 16 August 2011 18:02, universe sheep  wrote:

> Without a root permission, I can't install perl module through normal way
> such as CPAN. But I have to use this module(XML::Quote).
> I have tried to copy the .pm file to my own lib directory directly, but it
> says "can't locate loadable perl module ".
>
> Is there any other way to install perl modules without a root authority?
>
> Thanks.
>


Re: Verifying an e-mail address

2011-07-01 Thread Wernher Eksteen
On 27 June 2011 20:53,  wrote:

>I'd like to find a way to check if an e-mail address that is entered
> on a form is valid or, at the very least, just not invalid.  Checking CPAN,
> I ran across a module called Email::Verify::SMTP.  Has anyone used this
> before?  If so, what are your impressions?
>
>If this is not a good module, what would you recommend?
>
> Thanks,
> Marc
>

Hi,

Also have a look at this module if SPF is involved: Mail::SPF::Query

-Wernher


Re: String Formatting by Column

2011-06-28 Thread Wernher Eksteen
>
> That's exactly right. I meant that, if you were using an external file,
> you only needed to replace the line
>
> my $fh = *DATA;
>
> with
>
> open my $fh, '<', 'myfile.txt' or die $!;
>
> which is pretty much what you have done. Unfortunately I made a mistake
> and wrote
>
> while () {
>
> in the first loop, when it should be the same as the second loop which
> reads
>
> while (<$fh>) {
>
> My apologies.
>
> Rob
>

No apologies necessary,  I'm just very happy that I could figure it out and
resolve it without any help :)

And so I'm a little bit wiser thanks to your help! Like someone said before,
Rob you rock!

Wernher


Re: matplotlib

2011-06-28 Thread Wernher Eksteen
Ok well on second thought, MATLAB probably is MATLIB...

On 28 June 2011 20:10, Wernher Eksteen  wrote:

> I really don't know much about MATLIB, but looking on their site it doesn't
> seem free: http://www.mathworks.com/products/matlab/
>
> I stumbled on PDL by chance and remembered someone asking if Perl could do
> this and so shared in the hope it might help.
>
>
> On 28 June 2011 20:01, Brendan Gilroy  wrote:
>
>> Isn't MatPlotLib free as well? I don't think PDL's low cost is a
>> competitive
>> advantage for Perl over Python
>>
>> In this Perlmonks node: http://www.perlmonks.org/?node_id=347028 , the
>> GD::Graphs module, and the PGPlot (
>> http://search.cpan.org/search?query=pgplot&mode=all) and GnuPlot (
>> http://search.cpan.org/search?query=gnuplot&mode=allapplications) are
>> discussed. I don't know enough about your task (or about Perl to be
>> honest)
>> to know if those will help, but that is as far as my googling gets me.
>>
>> On Tue, Jun 28, 2011 at 1:00 PM, Wernher Eksteen 
>> wrote:
>>
>> > Maybe it is of relevance after all...
>> >
>> > PDL is "free software". The authors of PDL think that this concept has
>> > several advantages: everyone has access to the sources -> better
>> > debugging, easily adaptable to your own needs, extensible for your
>> > purposes, etc... In comparison with commercial packages such as MATLAB
>> > and IDL this is of considerable importance for workers who want to do
>> > some work at home and cannot afford the considerable cost to buy
>> > commercial packages for personal use.
>> >
>> > Wernher
>> >
>> > On Tue, Jun 28, 2011 at 6:58 PM, Wernher Eksteen 
>> > wrote:
>> > > Not sure if this is relevant, but I stumbled on this..
>> > http://pdl.perl.org/
>> > >
>> > > Wernher
>> > >
>> > > On Thu, Jun 23, 2011 at 9:30 AM, Sayth Renshaw <
>> flebber.c...@gmail.com>
>> > wrote:
>> > >> On Thu, Jun 23, 2011 at 6:32 AM, Bryan R Harris
>> > >>  wrote:
>> > >>>
>> > >>>
>> > >>> I much prefer perl to python given my recent forays into that
>> language
>> > >>> (python's regex is awful!), however it has an excellent plotting
>> > package
>> > >>> that is very similar to matlab but supports things like marker
>> alphas.
>> >  It's
>> > >>> called matplotlib, and requires scipy and numpy.
>> > >>>
>> > >>> PDL is the closest thing I see in perl, but it seems to be clunky
>> and
>> > makes
>> > >>> relatively ugly plots.
>> > >>>
>> > >>> Any thoughts on why that is?:
>> > >>>
>> > >>> (a) in python it's easier to make things like this
>> > >>> (b) python has more scientific users so it makes sense one would
>> build
>> > it
>> > >>> (c) perl users tend to be lazier and less likely to make something
>> like
>> > this
>> > >>> (d) somebody funded that development and happened to pay a python
>> guy
>> > >>> (e) ??
>> > >>>
>> > >>> Just curious, thanks for your thoughts.
>> > >>>
>> > >>> - Bryan
>> > >>>
>> > >>>
>> > >>>
>> > >>> --
>> > >>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> > >>> For additional commands, e-mail: beginners-h...@perl.org
>> > >>> http://learn.perl.org/
>> > >>>
>> > >>>
>> > >>>
>> > >>
>> > >> Not exactly sure personally. But here is an article that may be of
>> > interest.
>> > >>
>> > >> http://www.stat.washington.edu/~hoytak/blog/whypython.html
>> > >>
>> > >> Sayth
>> > >>
>> > >> --
>> > >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> > >> For additional commands, e-mail: beginners-h...@perl.org
>> > >> http://learn.perl.org/
>> > >>
>> > >>
>> > >>
>> > >
>> >
>> > --
>> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> > For additional commands, e-mail: beginners-h...@perl.org
>> > http://learn.perl.org/
>> >
>> >
>> >
>>
>
>


Re: matplotlib

2011-06-28 Thread Wernher Eksteen
I really don't know much about MATLIB, but looking on their site it doesn't
seem free: http://www.mathworks.com/products/matlab/

I stumbled on PDL by chance and remembered someone asking if Perl could do
this and so shared in the hope it might help.

On 28 June 2011 20:01, Brendan Gilroy  wrote:

> Isn't MatPlotLib free as well? I don't think PDL's low cost is a
> competitive
> advantage for Perl over Python
>
> In this Perlmonks node: http://www.perlmonks.org/?node_id=347028 , the
> GD::Graphs module, and the PGPlot (
> http://search.cpan.org/search?query=pgplot&mode=all) and GnuPlot (
> http://search.cpan.org/search?query=gnuplot&mode=allapplications) are
> discussed. I don't know enough about your task (or about Perl to be honest)
> to know if those will help, but that is as far as my googling gets me.
>
> On Tue, Jun 28, 2011 at 1:00 PM, Wernher Eksteen 
> wrote:
>
> > Maybe it is of relevance after all...
> >
> > PDL is "free software". The authors of PDL think that this concept has
> > several advantages: everyone has access to the sources -> better
> > debugging, easily adaptable to your own needs, extensible for your
> > purposes, etc... In comparison with commercial packages such as MATLAB
> > and IDL this is of considerable importance for workers who want to do
> > some work at home and cannot afford the considerable cost to buy
> > commercial packages for personal use.
> >
> > Wernher
> >
> > On Tue, Jun 28, 2011 at 6:58 PM, Wernher Eksteen 
> > wrote:
> > > Not sure if this is relevant, but I stumbled on this..
> > http://pdl.perl.org/
> > >
> > > Wernher
> > >
> > > On Thu, Jun 23, 2011 at 9:30 AM, Sayth Renshaw  >
> > wrote:
> > >> On Thu, Jun 23, 2011 at 6:32 AM, Bryan R Harris
> > >>  wrote:
> > >>>
> > >>>
> > >>> I much prefer perl to python given my recent forays into that
> language
> > >>> (python's regex is awful!), however it has an excellent plotting
> > package
> > >>> that is very similar to matlab but supports things like marker
> alphas.
> >  It's
> > >>> called matplotlib, and requires scipy and numpy.
> > >>>
> > >>> PDL is the closest thing I see in perl, but it seems to be clunky and
> > makes
> > >>> relatively ugly plots.
> > >>>
> > >>> Any thoughts on why that is?:
> > >>>
> > >>> (a) in python it's easier to make things like this
> > >>> (b) python has more scientific users so it makes sense one would
> build
> > it
> > >>> (c) perl users tend to be lazier and less likely to make something
> like
> > this
> > >>> (d) somebody funded that development and happened to pay a python guy
> > >>> (e) ??
> > >>>
> > >>> Just curious, thanks for your thoughts.
> > >>>
> > >>> - Bryan
> > >>>
> > >>>
> > >>>
> > >>> --
> > >>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > >>> For additional commands, e-mail: beginners-h...@perl.org
> > >>> http://learn.perl.org/
> > >>>
> > >>>
> > >>>
> > >>
> > >> Not exactly sure personally. But here is an article that may be of
> > interest.
> > >>
> > >> http://www.stat.washington.edu/~hoytak/blog/whypython.html
> > >>
> > >> Sayth
> > >>
> > >> --
> > >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > >> For additional commands, e-mail: beginners-h...@perl.org
> > >> http://learn.perl.org/
> > >>
> > >>
> > >>
> > >
> >
> > --
> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > For additional commands, e-mail: beginners-h...@perl.org
> > http://learn.perl.org/
> >
> >
> >
>


Re: String Formatting by Column

2011-06-28 Thread Wernher Eksteen
Hi Rob,

I wasn't quite sure at first what you meant by passing the file handle
 in the while loop when $fh already existed,
so I changed the code slightly like this:


my $file = "file.txt";
open(my $fh, "<", $file) or die $!;

while (<$fh>) {

Works like a charm, thanks again!

Regards,
Wernher

>
> Rob
>
>
> use strict;
> use warnings;
>
> use Fcntl 'SEEK_SET';
>
> my $format;
>
> my $fh = *DATA;  # Replace with the appropriate 'open my $fh, '<', ... or die 
> $!;
>
> # Remember the where the file begins, and then build the unpack pattern from
> # the first line continaining only hyphens and underscores
> #
> my $bof = tell $fh;
> while () {
>  chomp;
>  if (tr/- //c == 0 and tr/-// > 0) {
>    while (/-+/g) {
>      my ($beg, $len) = ($-[0], $+[0] - $-[0]);
>      $format .= "\@$beg A$len ";
>    }
>    last;
>  }
> }
>
> warn qq(Data will be upacked with a format of "$format"\n\n);
>
> # Now rewind to the beginning of the file, ignore anything that contains only
> # whitespace, and unpack every record according to the pattern that we just 
> built
> #
> seek $fh, $bof, SEEK_SET;
> while (<$fh>) {
>  next unless /\S/;
>  my @data = unpack $format;
>  print join ',', @data;
>  print "\n";
> }
>
>
> __DATA__
>
>
> CTX   Destination                                                             
> Enabled   Connection         Sync'ed-as-of-time
> ---   -   
> ---      --
> 1     pool://ZABRYDD01.localdomain/RDP_NEW_REP                                
> yes       Sat Jun 18 08:56   Fri Jun 24 06:37
> 2     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101    
> yes       Sat Jun 18 08:57   Fri Jun 24 08:01
> 4     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22     
> yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 5     pool://ZARDPDD01.localdomain/BRYREP                                     
> yes       Sat Jun 18 08:57   Fri Jun 24 07:01
> 8     dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31     
> yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 10    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421    
> yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 12    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5      
> yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> 13    dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60     
> yes       Sat Jun 18 08:57   Fri Jun 24 09:00
> ---   -   
> ---      --
>
> **OUTPUT**
>
> Data will be upacked with a format of "@0 A3 @6 A69 @78 A7 @88 A16 @107 A18 "
>
> "CTX","Destination","Enabled","Connection","Sync'ed-as-of-time"
> "---","-","---","","--"
> "1","pool://ZABRYDD01.localdomain/RDP_NEW_REP","","Sat Jun 18 08:56","Fri Jun 
> 24 06:37"
> "2","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101","yes","Sat
>  Jun 18 08:57","Fri Jun 24 08:01"
> "4","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22","yes","Sat
>  Jun 18 08:57","Fri Jun 24 09:00"
> "5","pool://ZARDPDD01.localdomain/BRYREP","yes","Sat Jun 18 08:57","Fri Jun 
> 24 07:01"
> "8","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31","yes","Sat
>  Jun 18 08:57","Fri Jun 24 09:00"
> "10","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421","yes","Sat
>  Jun 18 08:57","Fri Jun 24 09:00"
> "12","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5","yes","Sat
>  Jun 18 08:57","Fri Jun 24 09:00"
> "13","dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60","yes","Sat
>  Jun 18 08:57","Fri Jun 24 09:00"
> "---","-","---","","--"
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: matplotlib

2011-06-28 Thread Wernher Eksteen
Maybe it is of relevance after all...

PDL is "free software". The authors of PDL think that this concept has
several advantages: everyone has access to the sources -> better
debugging, easily adaptable to your own needs, extensible for your
purposes, etc... In comparison with commercial packages such as MATLAB
and IDL this is of considerable importance for workers who want to do
some work at home and cannot afford the considerable cost to buy
commercial packages for personal use.

Wernher

On Tue, Jun 28, 2011 at 6:58 PM, Wernher Eksteen  wrote:
> Not sure if this is relevant, but I stumbled on this.. http://pdl.perl.org/
>
> Wernher
>
> On Thu, Jun 23, 2011 at 9:30 AM, Sayth Renshaw  wrote:
>> On Thu, Jun 23, 2011 at 6:32 AM, Bryan R Harris
>>  wrote:
>>>
>>>
>>> I much prefer perl to python given my recent forays into that language
>>> (python's regex is awful!), however it has an excellent plotting package
>>> that is very similar to matlab but supports things like marker alphas.  It's
>>> called matplotlib, and requires scipy and numpy.
>>>
>>> PDL is the closest thing I see in perl, but it seems to be clunky and makes
>>> relatively ugly plots.
>>>
>>> Any thoughts on why that is?:
>>>
>>> (a) in python it's easier to make things like this
>>> (b) python has more scientific users so it makes sense one would build it
>>> (c) perl users tend to be lazier and less likely to make something like this
>>> (d) somebody funded that development and happened to pay a python guy
>>> (e) ??
>>>
>>> Just curious, thanks for your thoughts.
>>>
>>> - Bryan
>>>
>>>
>>>
>>> --
>>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>>> For additional commands, e-mail: beginners-h...@perl.org
>>> http://learn.perl.org/
>>>
>>>
>>>
>>
>> Not exactly sure personally. But here is an article that may be of interest.
>>
>> http://www.stat.washington.edu/~hoytak/blog/whypython.html
>>
>> Sayth
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: matplotlib

2011-06-28 Thread Wernher Eksteen
Not sure if this is relevant, but I stumbled on this.. http://pdl.perl.org/

Wernher

On Thu, Jun 23, 2011 at 9:30 AM, Sayth Renshaw  wrote:
> On Thu, Jun 23, 2011 at 6:32 AM, Bryan R Harris
>  wrote:
>>
>>
>> I much prefer perl to python given my recent forays into that language
>> (python's regex is awful!), however it has an excellent plotting package
>> that is very similar to matlab but supports things like marker alphas.  It's
>> called matplotlib, and requires scipy and numpy.
>>
>> PDL is the closest thing I see in perl, but it seems to be clunky and makes
>> relatively ugly plots.
>>
>> Any thoughts on why that is?:
>>
>> (a) in python it's easier to make things like this
>> (b) python has more scientific users so it makes sense one would build it
>> (c) perl users tend to be lazier and less likely to make something like this
>> (d) somebody funded that development and happened to pay a python guy
>> (e) ??
>>
>> Just curious, thanks for your thoughts.
>>
>> - Bryan
>>
>>
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>
> Not exactly sure personally. But here is an article that may be of interest.
>
> http://www.stat.washington.edu/~hoytak/blog/whypython.html
>
> Sayth
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: String Formatting by Column

2011-06-26 Thread Wernher Eksteen
Hi Rob,

Once again your expertise and willingness to help is astounding.

I appreciate the idea that everyone else is trying to force me into learning
a new concept I have never
encountered before by giving me pointers in the direction such as telling me
to look at pack and unpack
or the CSV related modules, which are all good, but I found that often
learning through example and then
take what I've learned and expand on that going forth usually works for me.

The fact that you went the extra mile and actually gave me a real example
based on what I need, not
only do I learn from this, but I also grasp it much quicker than having to
first learn the entire new concept
such as pack, unpack or the CSV related modules, but I also now have a very
good understanding from
which I can build on and have a good base from where I can dig deeper from
here.

Thank you very much for your assistance and literally showing me the ropes
and even explaining it so
that Perl newbies such as myself can understand it.

Perl is a great language and a great tool that is very useful in a wide
range of things, but grasping it's
power is often not easy for newcomers who want to know it, but don't always
have the time to reinvent
the wheel, which is why standing on the shoulders of giants who does
understand these things and who
are willing to share their expertise and guide newcomers such as myself so
that many more in future can
eventually do what you do and so have a "return of investment" by helping
the Perl community grow even
faster as to keep it obscured and out of reach for the norm.

Personally, I am a Java developer and Linux Admin of profession and don't
always have the time as much
as I would love to have digging into the finer details and aspects of
things, and understand that I will not and
cannot possibly know everything there is to know about any particular
subject, but know there are people such
as yourself out there willing to lend a hand and point those such as myself
not only in the right direction, but also
providing the map to get there. All I need to do is follow the road, and
then build my own maps based on what
I have learned from people such as yourself.

Regards,
Wernher

On 25 June 2011 19:02, Rob Dixon  wrote:

> On 24/06/2011 08:45, Wernher Eksteen wrote:
> >
> > I've attached a text file containing the original and required
> > format and avoid the format being lost by just pasting it in the
> > email body.
> >
> > The original format is separated by a space, but need to replace the
> > space with a comma, so it will become a comma delimited csv file
> > which I will then import to MS Excel.
> >
> > I'm not sure how to parse the "Connection" and "Sync'ed-as-of-time"
> > columns since the dates there in is in this format "Fri Jun 24
> > 06:37" which also separated by space, but the spaces in those
> > columns shouldn't be replaced by a comma. The date format in those
> > columns should remain the same.
> >
> > Also, is it possible to convert this directly into a MS Excel
> > document using Perl?
>
> Hello again Wernher.
>
> My first guess for this problem was to build an 'unpack' format based on
> the row of hyphens beneath the header captions. As it may still be
> useful, and well worth studying for similar applications, here is my
> alternative solution doing just that.
>
> The program grabs everything in the file that is aligned with the row
> of hyphens beneath the captions. It works by finding the first line in
> the file that contains only hyphens or spaces, and scanning that to
> build an unpack string using the @- and @+ arrays that hold the offsets
> of the start and end of the previous successful regex match.
>
> Unlike my previous solution, empty (all-space) fields are handled
> correctly: the 'A' unpack format discards trailing spaces, and my only
> proviso is that if you ever expect leading spaces in fields they must be
> trimmed explicitly.
>
> HTH,
>
> Rob
>
>
> use strict;
> use warnings;
>
> use Fcntl 'SEEK_SET';
>
> my $format;
>
> my $fh = *DATA;  # Replace with the appropriate 'open my $fh, '<', ... or
> die $!;
>
> # Remember the where the file begins, and then build the unpack pattern
> from
> # the first line continaining only hyphens and underscores
> #
> my $bof = tell $fh;
> while () {
>  chomp;
>  if (tr/- //c == 0 and tr/-// > 0) {
>while (/-+/g) {
>  my ($beg, $len) = ($-[0], $+[0] - $-[0]);
>  $format .= "\@$beg A$len ";
>}
>last;
>  }
> }
>
> warn qq(Data will be upacked with a format of "$format"\n\n)

Re: String Formatting by Column

2011-06-24 Thread Wernher Eksteen
Hi,

Thanks for the tip, will try to figure it out on the weekend and come back
if I'm
stuck.

Just a few questions before I try this...

Does these modules have the ability to add the commas in the way I need them
to be?

The CVS_XS.pm module seems more flexible/powerful than the CVS.pm one
or am I wrong?

Regards,
Wernher


On 24 June 2011 10:19, Dermot  wrote:

> On 24 June 2011 08:45, Wernher Eksteen  wrote:
> > Hi,
> >
> > I've attached a text file containing the original and required format and
> > avoid the format
> > being lost by just pasting it in the email body.
> >
> > The original format is separated by a space, but need to replace the
> space
> > with a comma,
> > so it will become a comma delimited csv file which I will then import to
> MS
> > Excel.
> >
> > I'm not sure how to parse the "Connection" and "Sync'ed-as-of-time"
> columns
> > since the dates
> > there in is in this format "Fri Jun 24 06:37" which also separated by
> space,
> > but the spaces in
> > those columns shouldn't be replaced by a comma. The date format in those
> > columns should
> > remain the same.
> >
> > Also, is it possible to convert this directly into a MS Excel document
> using
> > Perl?
>
> Yes, you can achieve all your goals with perl. Have a look and
> Text::CSV_XS[1] or Text::CSV[2]. They will read the file correctly and
> write the file out for you with any separator you want. BTW, you want
> quotes around each field so as not to confuse you spreadsheet program.
> Writing the file into XLS format would require another module but I'll
> leave others to make that recommendation.
>
> Perhaps you could have a look at those, try and write something and
> when, or if, you get stuck, come back to the list showing the code
> you've got and get some pointers.
>
> Thanks,
> Dermot.
>
>
> 1) http://search.cpan.org/~hmbrand/Text-CSV_XS-0.82/CSV_XS.pm
> 2) http://search.cpan.org/~makamaka/Text-CSV-1.21/lib/Text/CSV.pm
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


String Formatting by Column

2011-06-24 Thread Wernher Eksteen
Hi,

I've attached a text file containing the original and required format and
avoid the format
being lost by just pasting it in the email body.

The original format is separated by a space, but need to replace the space
with a comma,
so it will become a comma delimited csv file which I will then import to MS
Excel.

I'm not sure how to parse the "Connection" and "Sync'ed-as-of-time" columns
since the dates
there in is in this format "Fri Jun 24 06:37" which also separated by space,
but the spaces in
those columns shouldn't be replaced by a comma. The date format in those
columns should
remain the same.

Also, is it possible to convert this directly into a MS Excel document using
Perl?

Many thanks!

Regards,
Wernher
Original Format
===

CTX   Destination 
Enabled   Connection Sync'ed-as-of-time
---   -   
---      --
1 pool://ZABRYDD01.localdomain/RDP_NEW_REP
yes   Sat Jun 18 08:56   Fri Jun 24 06:37
2 dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101
yes   Sat Jun 18 08:57   Fri Jun 24 08:01
4 dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22 
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
5 pool://ZARDPDD01.localdomain/BRYREP 
yes   Sat Jun 18 08:57   Fri Jun 24 07:01
8 dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31 
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
10dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
12dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5  
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
13dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60 
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
15dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test767
yes   Sat Jun 18 08:56   Fri Jun 24 08:01
18dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test83 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
19dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test91 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
20dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test10 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
23dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test14 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
25dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test12 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
26dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test14 
yes   Sat Jun 18 08:56   Fri Jun 24 09:00
27dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test12 
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
28dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test11 
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
31dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test167
yes   Sat Jun 18 08:57   Fri Jun 24 09:00
---   -   
---      --


Required Format (comma delimited)
=

CTX,Destination,Enabled,Connection,Sync'ed-as-of-time,
---,-,---,,--
1,pool://ZABRYDD01.localdomain/RDP_NEW_REP,yes,Sat Jun 18 08:56,Fri Jun 24 06:37
2,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test101,yes,Sat 
Jun 18 08:57,Fri Jun 24 08:01
4,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test22,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
5,pool://ZARDPDD01.localdomain/BRYREP,yes,Sat Jun 18 08:57,Fri Jun 24 07:01
8,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test31,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
10,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test421,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
12,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test5,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
13,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test60,yes,Sat 
Jun 18 08:57,Fri Jun 24 09:00
15,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test767,yes,Sat 
Jun 18 08:56,Fri Jun 24 08:01
18,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test83,yes,Sat 
Jun 18 08:56,Fri Jun 24 09:00
19,dir://ZARDPDD01.localdomain/backup/ZABRYDD01REP/linux/backup/test91,yes,Sat 
Jun 18 08:56,Fri Jun 24 09:00
20,dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test10,yes,Sat 
Jun 18 08:56,Fri Jun 24 09:00
23,dir://ZABRYDD01.localdomain/backup/ZARDPDD01REP/linux/backup/test14,yes,Sat 
Jun 18 08:56,Fri Jun 24 09:0

Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-04 Thread Wernher Eksteen
> Hello Wernher,

Hi Chris,

> Rob's code could be reconfigured slightly to do so, but requires a
> different approach.  I will paste it below.

Ok, thanks.

> One change I made was to make the *values* of %hash1 an array ref as I
> thought this was how the hash was originally constructed. If the value
> for %hash1 was a string as in Rob's hash, the code below could be
> altered slightly to perform the task as well.

Ah yes, to make the values of %hash1 an array does make more sense.

> You said 'But, I plan to add things like "disk size",  "disk size
> used" and "disk size free" numeric values next to each partition mount '
> It is good to build up a program in small steps and test as you go,
> but it is also helpful to have a large view of the problem so that you
> won't create data structures that work for the first stages of the
> program but fail to accomodate later alterations. You really kinda
> need to have the big picture at the start.

You are right, thank you very much.

> Chris
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> # I changed the value of the hash to an array (ref). Rob had a string
> here
> my %hash1 = (
>  emcpowera  => [qw/sdbd sddg sdfj sdhm/],
>  emcpoweraa => [qw/sdae sdch sdek sdgn/],
>  emcpowerbc => [qw/sdb sdbe sddh sdfk/],
>  emcpowerc  => [qw/sdbb sdde sdfh sdhk/],
>  emcpowerd  => [qw/sdba sddd sdfg sdhj/],
>  emcpowerz  => [qw/sdba sddd sdfg sdhj/]
> );
>
>
> my %hash2 = (
>  emcpowera1  => "/dwpdb006",
>  emcpoweraa1 => "/dwpdb033",
>  emcpowerbc1 => "/s00_11",
>  emcpowerbc2 => "/utl_file_dir",
>  emcpowerc1  => "/odsdb006",
>  emcpowerd1  => "/odsdb005",
> );
>
> my %seen;
> for my $key (sort keys %hash2) {
>        (my $k1 = $key) =~ s/\d+\z//;
>        if (my $aref = $hash1{ $k1 }) {
>
>                my $string = "$k1 @$aref";
>                $string = ' ' x length($string) if $seen{$k1}++;
>
>                print "$string\t$key $hash2{$key}\n";
>        }
> }
>
> delete @hash1{ keys %seen };
> print "$_ @{ $hash1{$_} }\n" for sort keys %hash1;

Chris, thank you so very much for this, it does exactly the way I need it!!!

I have learned a great deal of things since I joined this list last
week Friday the 1st.

Kind regards,
Wernher Eksteen

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
Hi Shawn,

Thank you very much,

Shown from your code below and my print1 and prin2 comments below:

print1 correctly prints the following:

emcpoweraa sdae sdch sdek sdgn /dwpdb033
emcpowerd sdba sddd sdfg sdhj /odsdb005
emcpowerc sdbb sdde sdfh sdhk /odsdb006
emcpowerbc sdb sdbe sddh sdfk /s00_11
emcpowerbc sdb sdbe sddh sdfk /utl_file_dir
emcpowera sdbd sddg sdfj sdhm /dwpdb006

print2 incorrectly prints the following:

emcpoweraa sdae sdch sdek sdgn
emcpowerd sdba sddd sdfg sdhj
emcpowerc sdbb sdde sdfh sdhk
emcpowerbc sdb sdbe sddh sdfk
emcpowera sdbd sddg sdfj sdhm

Print2 should only print this line:
emcpowerz" => "sdba sddd sdfg sdhj

my( %hash3, %nothash );
my $found = 0;
while( my( $ikey, $ival ) = each( %hash1 ) ) {
  while( my( $jkey, $jval ) = each( %hash2 ) ) {
 (my $mkey = $jkey ) =~ s/[0-9]//g;
 if( $ikey eq $mkey ) {
$hash3{ $ikey } = $ival . " " . $jval;
$found = 1;
print "$ikey $ival $jval\n"; # < print1
 }
  }
  if( $found == 1 ) {
 $nothash{ $ikey } = $ival;
 $found = 0;
 print "$ikey $ival\n"; # <-- print2
  }
}

Many thanks for your help!

Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
Hi John,

>%hash1
>   emcpowera   sdbd sddg sdfj sdhm
>emcpoweraa  sdae sdch sdek sdgn
>emcpowerbc  sdb sdbe sddh sdfk
>emcpowerc   sdbb sdde sdfh sdhk
>emcpowerd   sdba sddd sdfg sdhj
>
>%hash2
>emcpowera1  /dwpdb006
>   emcpoweraa1 /dwpdb033
>emcpowerbc1 /s00_11
>emcpowerbc2 /utl_file_dir
>emcpowerc1  /odsdb006
>emcpowerd1  /odsdb005
>
>This is what the end result should look like:
>
>%hash3
>emcpowera   sdbd sddg sdfj sdhm  emcpowera1  /dwpdb006
>emcpoweraa  sdae sdch sdek sdgn  emcpoweraa1 /dwpdb033
>emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
>   sdba sddd sdfg sdhj  emcpowerbc2 /utl_file_dir
>   ^^^
>  Why is this list
>

Sorry that should be like this instead:

emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
sdb sdbe sddh sdfk   emcpowerbc2 /utl_file_dir

>
>emcpowercsdbb sdde sdfh sdhk  emcpowerc1  /odsdb006
>emcpowerdsdba sddd sdfg sdhj  emcpowerd1  /odsdb005
>
>^^^
>the same as this list?
>

 That is now correct as is.

>
>emcpowerzsdbg sddv sdfd sdht
>
>   ^^^
>   Where did this list come from?
>

Once again, sorry I should have made it like so:

%hash1
emcpowera   sdbd sddg sdfj sdhm
emcpoweraa  sdae sdch sdek sdgn
emcpowerbc  sdb sdbe sddh sdfk
emcpowerc   sdbb sdde sdfh sdhk
emcpowerd   sdba sddd sdfg sdhj
emcpowerzsdbg sddv sdfd sdht   <- That disk is the only disk
(emcpowerz in this example) that doesn't have a matching partition in
%hash2.

Thank you for picking up my errors!

Kind regards,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
> I suggest you reduce your tab size from eight characters, which leave
> your code spread out and less readable. Four or two is more usual
> nowadays.

Thank you, I will do so from now on.

> Meaningful variable names are also important. Using $i as the key to
> %hash1 and $b as the key to %hash2 is a very bad idea: both have
> different conventional uses and $b is a special variable used internally
> by Perl.

Thanks you, I will add more descriptive names in future. I didn't know $b
is a special internal variable used by Perl.

> Long chains of concatenated strings can be improved visually by
> interpolation:
>
>  push @matched, "$i $hash1{$i} $b $hash2{$b}\n";
>
> or formatting:
>
>  push @matched, sprintf "%s %s %s %s\n", $i, $hash1{$i}, $b, $hash2{$b};

Wow, thanks!

> As for an improved version, your main purpose seems to be to combine
> data that belongs under the same /emcpower.*/ prefix. The program below
> does this by modifying %hash1, rather than building two new arrays as
> yours does. If this is unacceptable then come back to us.

This is acceptable, thank you!

> The program iterates over the records in %hash2, removes the decimals
> from the end of the key, and uses the result to select the record in
> %hash1 that should be appended to.

Thank you, I definitely still need to familiarize myself better with
hashes and I
am working on getting there. From the likes of you and others in this
list I will
achieve this goal much quicker than just by myself.

> HTH,

Yes, it does very much, thank you!

> Rob
>
>
>
> use strict;
> use warnings;
>
> my %hash1 = (
>  emcpowera  => "sdbd sddg sdfj sdhm",
>  emcpoweraa => "sdae sdch sdek sdgn",
>  emcpowerbc => "sdb sdbe sddh sdfk",
>  emcpowerc  => "sdbb sdde sdfh sdhk",
>  emcpowerd  => "sdba sddd sdfg sdhj",
>  emcpowerz  => "sdba sddd sdfg sdhj",
> );
>
> my %hash2 = (
>  emcpowera1  => "/dwpdb006",
>  emcpoweraa1 => "/dwpdb033",
>  emcpowerbc1 => "/s00_11",
>  emcpowerbc2 => "/utl_file_dir",
>  emcpowerc1  => "/odsdb006",
>  emcpowerd1  => "/odsdb005",
> );
>
> for my $key2 (keys %hash2) {
>  (my $key1 = $key2) =~ s/\d+\z//;
>  if ($hash1{$key1}) {
>    $hash1{$key1} = "$hash1{$key1} $key2 $hash2{$key2}";
>  }
> }
>
> foreach my $key1 (sort keys %hash1) {
>  print "$key1 $hash1{$key1}\n";
> }
>
> **OUTPUT**
>
> emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006
> emcpoweraa sdae sdch sdek sdgn emcpoweraa1 /dwpdb033
> emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11 emcpowerbc2 /utl_file_dir
> emcpowerc sdbb sdde sdfh sdhk emcpowerc1 /odsdb006
> emcpowerd sdba sddd sdfg sdhj emcpowerd1 /odsdb005
> emcpowerz sdba sddd sdfg sdhj
>
>

This is really totally awesome, thank you so very much!

I really like what you have done with this line, it's very cool!

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11 emcpowerbc2 /utl_file_dir

But, I plan to add things like "disk size",  "disk size used" and
"disk size free" numeric values
next to each partition mount ( emcpowerbc1 /s00_11 ) and (emcpowerbc2
/utl_file_dir) in this case,
so I would prefer to have it like this instead:

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
   emcpowerbc2 /utl_file_dir

or

emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
emcpowerbc sdb sdbe sddh sdfk emcpowerbc2 /utl_file_dir

Could you please show me how to change your excellent code to achieve
either one of these instead?

Many thanks!
Wernher

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
> so, lets do what you asked (i like hashes better anyway :) )
>
> my %hash3, %nothash;
> my $found = 0;
> while( my( $ikey, $ival ) = each( %hash1 ) ) {
>   while( my( $jkey, $jval ) = each( %hash2 ) ) {
>      if( ( $ikey == $jkey ) and ( $ival == $ikey ) ) {
>         $hash3{ $ikey } = $ival;
>         $found = 1;
>      }
>   }
>   if( $found == 0 ) {
>   %nothash{ $ikey } = $ival;
>   $found = 0;
> }

Thanks Shawn, I'm still trying to figure out what you're doing.., but
get this error
when I run the script.

syntax error at test2.pl line 32, near "%nothash{"
syntax error at test2.pl line 35, near "}"

Wernher

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
Got this to work, but is there a better way to do this?

#!/usr/bin/perl

use strict;
use warnings;

my ( $val, @matched, @unmatched, %hash1, %hash2 );

%hash1 = (
"emcpowera" => "sdbd sddg sdfj sdhm",
"emcpoweraa" => "sdae sdch sdek sdgn",
"emcpowerbc" => "sdb sdbe sddh sdfk",
"emcpowerc" => "sdbb sdde sdfh sdhk",
"emcpowerd" => "sdba sddd sdfg sdhj",
"emcpowerz" => "sdba sddd sdfg sdhj"
);

%hash2 = (
"emcpowera1" => "/dwpdb006",
"emcpoweraa1" => "/dwpdb033",
"emcpowerbc1" => "/s00_11",
"emcpowerbc2" => "/utl_file_dir",
"emcpowerc1" => "/odsdb006",
"emcpowerd1" => "/odsdb005"
);

foreach my $i (keys(%hash1)) {

   foreach my $b (keys(%hash2)) {

   if ($b =~ /$i[0-9]+/) {
   $val = $b;
   push @matched, "$i" . " $hash1{$i} " . "$b" . "
$hash2{$b} " . "\n";
   }
   }

   if (not $i =~ /$val*/) {
   push @unmatched, "$i" . " $hash1{$i} " . "\n";
   }
}

print " @matched";
print " @unmatched\n";

--- RESULT ---

 emcpoweraa sdae sdch sdek sdgn emcpoweraa1 /dwpdb033
 emcpowerd sdba sddd sdfg sdhj emcpowerd1 /odsdb005
 emcpowerc sdbb sdde sdfh sdhk emcpowerc1 /odsdb006
 emcpowerbc sdb sdbe sddh sdfk emcpowerbc1 /s00_11
 emcpowerbc sdb sdbe sddh sdfk emcpowerbc2 /utl_file_dir
 emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006
 emcpowerz sdba sddd sdfg sdhj


--
Regards.
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Perl Hash Comparison and concatenate result from %hash2 compared to %hash1 into %hash3

2011-04-03 Thread Wernher Eksteen
Hi,

How do I compare the column 1 in %hash2, with column 1 in %hash1 so
that when a match is found
to append or concatenate the hash key (column 1) and it's associated
values from %hash2 with that
of %hash1 and build a new hash %hash3 as the end result.

%hash1
emcpowera   sdbd sddg sdfj sdhm
emcpoweraa  sdae sdch sdek sdgn
emcpowerbc  sdb sdbe sddh sdfk
emcpowerc   sdbb sdde sdfh sdhk
emcpowerd   sdba sddd sdfg sdhj

%hash2
emcpowera1  /dwpdb006
emcpoweraa1 /dwpdb033
emcpowerbc1 /s00_11
emcpowerbc2 /utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005

This is what the end result should look like:

%hash3
emcpowera    sdbd sddg sdfj sdhm  emcpowera1  /dwpdb006
emcpoweraa  sdae sdch sdek sdgn  emcpoweraa1 /dwpdb033
emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
                    sdba sddd sdfg sdhj  emcpowerbc2 /utl_file_dir
emcpowerc    sdbb sdde sdfh sdhk  emcpowerc1  /odsdb006
emcpowerd    sdba sddd sdfg sdhj  emcpowerd1  /odsdb005
emcpowerz    sdbg sddv sdfd sdht

--

Thanks,
Wernher

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-03 Thread Wernher Eksteen
Hi,

Thank you for showing me a better way to run the while loops, not
using the foreach loop, but the for loop and some
extra regex ways to accomplish things. Otherwise it prints out exactly
what I had before :-)

I have attached my request in a text file this time, to make it more
readable without email screwing up
the text alignment and formatting.

Please have a look and let me know how this could be done.

Basically, I need to compare the emcpower\w+\d partitions names from
the %allLocalMountedDisks hash
to that of the emcpower\w+ disks from the %allEmcMountedDisks hash.
I'm not sure, but I think the
emcpower\w+\d and emcpower\w+  names are the hash keys...? If so, then
I don't want to compare the
values/result of the hash keys, I just want to compare the hash keys
against another, and if matched
with =~ to append the key and values of %allLocalMountedDisks with the
matched keys and found values
found in %allLocalMountedDisks.

I know Perl is powerful, but until I understand Perl and hashes much
better I can't get this to work and
hope someone on this list can help me out so I can learn from that.

Please have a look at the attach text file where I try to explain as best I can.

Many thanks.

Kind regards,
Wernher
Thank you for correcting and showing me a better different way to do the while 
loops, but instead of the
two for loops printing the following out:

emcpowera   sdbd sddg sdfj sdhm   #  <- [1st for loop output]
emcpoweraa  sdae sdch sdek sdgn   # These the available emcpower disks and 
their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowerc   sdbb sdde sdfh sdhk
emcpowerd   sdba sddd sdfg sdhj   # <- [end of 1st for loop]

emcpowera1  /dwpdb006 # <- [2nd for loop output]
emcpoweraa1 /dwpdb033 # These are the local emcpower* disk 
paritions and their local mount points.
emcpowerbc1 /s00_11   # Note that the emcpowerbc disk has 2 
partitions, 1 and 2 below.
emcpowerbc2 /utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005 # <- [end of 2nd for loop]

How can I match the emcpower partitions ie: emcpowera1 as a result from the 2nd 
loop, to the emcpower disks 
ie: emcpowera as a result from the 1st loop.

What I would like to do is to compare what (emcpower\w+\d) partitions ie: 
emcpowera1 (seen from the output of
the 2nd for loop), where mounted against the available list of the 
(emcpower\w+) disk devices ie: emcpowera
(found in the 1st output) and then match on the (emcpower\w+) disk found (from 
1st output). The result of the 
output of the matched partition found (2nd output) must concatenate to the 
result of the emcpower disk (1st output), 
and then also show the (emcpower\w+) disks (from 1st output) that wasn't 
matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera (from 1st 
output) and display the result 
along with the mount point that was found for emxpowera1 like this:

   emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks ie: emxpowerz that wasn't matched by a 
(emxpower\w+\d) partition ie: emxpowerz1, 
to then only display normal output found in loop 1, because it doesn't have a 
matching partition ie:

emcpowerz sdbg sddv sdfd sdht

If there are more than one (emcpower\w+\d) partition, to display the output for 
example like this:

emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11
emcpowerbc2 /utl_file_dir

So the end result from the above should for example display:

emcpowera   sdbd sddg sdfj sdhm  emcpowera1  /dwpdb006
emcpoweraa  sdae sdch sdek sdgn  emcpoweraa1 /dwpdb033
emcpowerbc  sdb sdbe sddh sdfk   emcpowerbc1 /s00_11
sdba sddd sdfg sdhj  emcpowerbc2 /utl_file_dir
emcpowerc   sdbb sdde sdfh sdhk  emcpowerc1  /odsdb006
emcpowerd   sdba sddd sdfg sdhj  emcpowerd1  /odsdb005
emcpowerz   sdbg sddv sdfd sdht
-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Re: How can I do this in Perl?

2011-04-02 Thread Wernher Eksteen
Hi,

The Perl script (shown further down below) gives me the following
output (without the comments).
Please note that this is not the complete output, I only show the
necessary detail for sake of clarity.

emcpowerasdbd sddg sdfj sdhm   #  <- [1st foreach loop output]
emcpoweraa  sdae sdch sdek sdgn  # These the available
emcpower disks and their associate devices
emcpowerbc  sdb sdbe sddh sdfk
emcpowercsdbb sdde sdfh sdhk
emcpowerdsdba sddd sdfg sdhj
emcpowera1  /dwpdb006  #  <- [2nd foreach loop output]
emcpoweraa1/dwpdb033  # These are the local
emcpower* disk paritions and their local mount points.
emcpowerbc1/s00_11  # Note that the
emcpowerbc disk has 2 partitions, 1 and 2 below.
emcpowerbc2/utl_file_dir
emcpowerc1  /odsdb006
emcpowerd1  /odsdb005

What I would like to do is to compare what (emcpower\w+\d) partitions
(seen from the output of the 2nd foreach loop), where mounted against
the available list of the (emcpower\w+) disk devices (found in the 1st
output) and then match on the (emcpower\w+) disk found (from 1st
output). The result of the output of the matched partition found (2nd
output) must concatenate to the result of the emcpower disk (1st
output), and then also show the (emcpower\w+) disks (from 1st output)
that wasn't matched, if any.

In other words,

If emcpowera1 was found (from 2nd output), to match with emcpowera
(from 1st output) and display the result as follow:

emcpowera sdbd sddg sdfj sdhm emcpowera1 /dwpdb006

If there are any (emcpower\w+) disks that wasn't matched by a
(emxpower\w+\d) partition, to then display that normally like ie:

 emcpowerz sdbd sddg sdfj sdhm

If there are more than one (emcpower\w+\d) partition, to display the
output for example like this:

 emcpowerbc  sdb sdbe sddh sdfk  emcpowerbc1 /s00_11

emcpowerbc2 /utl_file_dir

I have included comments in the script to make it as clear as possible.

I can send the raw input for both $powermt and $mount if you need
them, just let me know.

==

<---script begin--->
#!/usr/bin/perl

use strict;
use warnings;

my $powermt = '/sbin/powermt display dev=all';
my $mount = '/bin/mount';

open my $emcDisks, '-|', $powermt or die "Could not execute powermt: $!";
open my $localDisks, '-|', $mount or die "Could not execute mount: $!";

my ($emcDevices, $localSdDevices);
my (@allLocalEmcDisks, @allLocalSdDisks, @allLocalMountedDevices);
my (%allEmcMountedDisks, %allLocalMountedDisks);

# Locate all available emcpower* disks and all sd* disks associated
with each EMC PowerPath disk.
while (my $i = <$emcDisks>) {
 if ( $i =~ /name=(emcpower\w+)/ ) {
   $emcDevices = $1; # $1 = emcpowerbc
 } elsif ( $i =~ /\blpfc\s+(sd\w+)/ ) { # $i = (sdb, sdbe, sddh, sdfk)
   push @{$allEmcMountedDisks{$emcDevices}}, $1; # hash =>
emcpowerbc[sdb, sdbe, sddh, sdfk]
 }
# Locate all local mounted /dev/emcpower* partitions and all
local mounted /dev/sd* disk partitions
while (my $b = <$localDisks>) {
if ($b =~ /\/dev\/(emcpower\w+\d)/) {
push @allLocalMountedDevices, $1; # $1 = emcpowerbc1
@allLocalEmcDisks = split (/\s+/, $b); # $b =
/dev/emcpowerbc1 on /s00_11 type ext3 (rw,acl,user_xattr)
push @{$allLocalMountedDisks{$1}},
$allLocalEmcDisks[2]; # hash => [emxpowerbc1, /s00_11]
} elsif ($b =~ /\/dev\/(sd\w+\d)/) {
push @allLocalMountedDevices, $1; # $1 = sdi1
@allLocalSdDisks = split (/\s+/, $b); # $b =
/dev/sdi1 on /dwpdb039 type ext3 (rw,acl,user_xattr)
push @{$allLocalMountedDisks{$1}},
$allLocalSdDisks[2]; # hash => [sdi, /dwpdb039]
}
}
}

# [1st foreach loop]
# Print each available emcpower* disks with their associated sd* disks
on the same line.
foreach my $i (sort keys %allEmcMountedDisks) {
printf "%s\t%s\n", $i, join(' ', @{$allEmcMountedDisks{$i}});
}

# [2nd foreach loop]
# Print each local mouted disk found with it's mount point on the same line.
foreach my $i (sort keys %allLocalMountedDisks) {
printf "\n%s %s\n", $i, join ' ', @{$allLocalMountedDisks{$i}};
}

<---script end--->
==

Regards,
Wernher Eksteen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
> that * isn't doing what you think it does. perl regexes are not shell
> globs. it happens to work anyway since the tokens are unique
> enough. read perlretut to learn perl regexes.
>
> what have you tried so far? you know enough perl to get the array of
> lines and loop over that. in english (or your native tongue), just
> describe how you would do it to get to your goal. write it down. it is
> only a few steps. then it will be easier to convert that to the perl
> needed to accomplish it. if you then have more troubles, post your code
> here and you will get help. a clue: you need a hash and its values will
> be array references. read perlreftut, perllol and perldsc for more on
> that.
>
> uri

Thanks Uri, I will take this into consideration and learn from this
going forward
and also make sure I understand what Rob's answer actually does and compare
notes and reference with the likes of perltut etc.

Kind regards,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
> Please always 'use strict' and 'use warnings', and consequently declare
> all of your variables. That way most straightforward problems will be
> solved my Perl before ever reaching his list.

Thanks, I will remember to do so for future.

> It is better to open a pipe to a child process running your command,
> rather than read all the output into an array and process that. I
> suggest something like the program below, which builds a hash of the
> device/disk relationship and prints it out at the end.
>
> HTH,
>
> Rob

Thanks Rob, this works fantastic!

Regards,
Wernher Eksteen

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




How can I do this in Perl?

2011-04-01 Thread Wernher Eksteen
Hi,

>From the folowing list is a result of the @power array, when run
through the foreach loop:

Pseudo name=emcpowerd
  1 lpfc  sdba SP A7 active  alive  0  0
  1 lpfc  sddd SP B7 active  alive  0  0
  3 lpfc  sdfg SP B6 active  alive  0  0
  3 lpfc  sdhj SP A6 active  alive  0  0
Pseudo name=emcpowerc
  1 lpfc  sdbb SP A7 active  alive  0  0
  1 lpfc  sdde SP B7 active  alive  0  0
  3 lpfc  sdfh SP B6 active  alive  0  0
  3 lpfc  sdhk SP A6 active  alive  0  0
Pseudo name=emcpoweraz
  1 lpfc  sdbh SP B7 active  alive  0  0
  3 lpfc  sddk SP B6 active  alive  0  0
  1 lpfc  sde  SP A7 active  alive  0  0
  3 lpfc  sdfn SP A6 active  alive  0  0

>From the list above, how can Perl assign the sd* disks to it's
relevant emcpower device, so that the output shows this:

emcpowerdsdba sddd sdfg sdhj
emcpowercsdbb sdde sdfh sdhk
emcpoweraz  sdbh sddk sde sdfn

This is how the @power array was obtained:

$powermt = 'powermt display dev=all';
@power = `$powermt`;

foreach my $i (@power) {
   if (($i =~ /emcpower*/) || ($i =~ /lpfc*/)) {
   print $i;
   }
}

Thanks,
Wernher

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/