I was thinking of using a hash of arrays b/c I want to look-up each array by a certain string and that string would the % string. My goal is to populate a hash of some sort with the % string and its associated F string. Here is the data file:
1 2005/01/20 15:39 17 2% -il-o-b----- sg F01000 2 2005/01/20 15:53 14 1% -il-o-b----- sg F01001 3 2005/01/18 09:53 2 0% -il-o-b----- sg F01002 4 2005/02/04 16:41 196 100% -il-o-b----f sg F01003 5 2005/02/05 21:13 305 100% -il-o-b----f sg F01004
#!/usr/bin/perl use strict; use warnings; $ENV{"PATH"} = qq(/opt/SUNWsamfs/sbin:/usr/bin:/usr/sbin:/usr/local/log); open (V4, "samcmd v4 2>&1 |" ) or die "unable to open pipe... Broken? $!"; my %HoA = (); my $i =0; foreach (<V4>) {
> s <sg> (); ^ The whitespace there will not work for all versions of Perl. Are you sure that it works for you?
> s {\-*} ()g;
The hyphen is not special in a regular expression, it does not need to be escaped. You are telling the substitution operator to replace all zero occurrences of '-' which is unnecessary.
$ perl -Mre=debug -e'$_ = q[ 1 2005/01/20 15:39 17 2% -il-o-b----- sg F01000]; s{-*} ()g;' 2>&1 | grep -c 'Match successful'
55
$ perl -Mre=debug -e'$_ = q[ 1 2005/01/20 15:39 17 2% -il-o-b----- sg F01000]; s{-+} ()g;' 2>&1 | grep -c 'Match successful'
4
As you can see the regex '-*' matches 55 times while the regex '-+' only matches 4 times.
Besides, it would be more efficient to use the transliteration operator.
tr/-//d;
s {\w+} ();
> $HoA{$i++} = (split)[-1] if (m/f01(\d+) && (\d+%) /gi );
You are storing the value of $i as the key which starts at 0 and is incremented for each line of input so why not just use an array and push the values onto it? You have included the string ' && ' in your regular expression but I don't see that string anywhere in your data? You are using capturing parentheses in the regular expression but you are not using those captured strings anywhere?
} close (V4) or die "unable to close pipe $!"; print "\n";
for my $d (keys %HoA) { print "$d: @{ $HoA{$d} }\n";
You are trying to use a scalar value ($HoA{$d}) as an array which strict should complain about.
}
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>