Am Montag, 2. Mai 2005 09.44 schrieb John Doe: > 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?
ok, here some code (you have to adapt it to your needs): === test5.pl === #!/usr/bin/perl use warnings; use strict; my @lines=split "\n", <<EOF; 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 EOF my %lookup; foreach (@lines) { my @fields=split /\s+/; push @{$lookup{$fields[4]}}, $fields[7]; } print join "\n", map {$_.": ".(join ", ", @{$lookup{$_}})} sort {$a <=> $b} keys %lookup; print "\n"; === end test5 pl === This prints: 0%: F01002 1%: F01001 2%: F01000 100%: F01003, F01004 [...] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>