Am Montag, 2. Mai 2005 03.49 schrieb [EMAIL PROTECTED]: > John, > > the reg exp s <-+> (); > ^ > was changed to > > y/sg//;; > y/-//d; > s{\w+} (); > to exclude the spaces and use y... thx > why are thre operators y or tr more efficient since these operators do not > use pattern matching?
Don't know the internal details, but tr needs no backtracking, capturing and such, it can simply take a char after the other and replace it with another one. So the implementation of the algorithm must be much much easier. > Originally I was using an array, actually 2 arrays one with all f string s > and one with all % strings. > To me it makes more sense to use a hash b/c each F string needs to be > pulled with its associative n% string. > This is why I want to populate a hash of arrays. Would another strategy be easier and more efficient to fulfill this requirement? * If the format of all your data lines is "consistent", you could use split on \s+ to get the data fields instead of a tr/m cascade. * Then, if I understand you correctly, you wantto build a hash with % keys and F... values. This could be done with code like push @{$lookup_hash{$pct_value}}, $F_value; eventually, you even want a 2nd level hash with the F field number as key, if the F values are unique over the whole file and the last field alway begins with an F. Or am I overlooking something? hth, joe > Below is what is should of read for my population of the hash. > > $HoA{$i++} = (split)[-1] if (m/f01(\d+)(\d+%) /gi ); > ciao, > derek : ) [...] > [EMAIL PROTECTED] wrote: > > 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 [...] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>