in reply to counting lines in perl
(One could likely make this more brief at the expense of readability.)while (<>){ $i++; chomp; $lines[$i]=$_; $times{$lines[$i]}++ if $lines[$i] ne $lines[$i-1]; }; @keys = keys %times; @values = values %times; while (@keys) { print pop(@values), ': ', pop(@keys), "\n"; }
|
|---|