my %lines; while (<>) { my ($key) = ( /^(\S+)/ ); # captures first token, assigns that to +$key push @{$lines{$key}}, $_; # (update: fixed missing "}") } for (sort keys %lines) { my $nlines = scalar @{$lines{$_}}; print "$nlines lines keyed by $_ :\n"; print " First line is: $lines{$_}[0]"; print " Last line is: $lines{$_}[$nlines-1]"; }
In reply to Re: pushing similar lines into arrays
by graff
in thread pushing similar lines into arrays
by Phydro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |