heroic one liners

quidity on 2006-06-26T16:46:50

You know you've been a little too heroic with a one liner when you realise you should have used more modules:



perl -MDateTime -wne'next if $_ lt "2006 04"; m{2006 (\d+) (\d+) \d+ \d+ \d+\.\d+ (-?\d+.\d+)} or next; my $dt = DateTime->new(year=>2006, month=>$1, day => $2); my $t = +$3; my $d = $days{$dt->day_of_year} = $days{$dt->day_of_year} || {}; $d->{min} = min($dt->{min}, $t); $d->{max} = max($d->{max}, $t); $d->{sum} += $t; $d->{cnt}++; sub min {$_[0] ? ($_[0] < $_[1] ? $_[0] : $_[1]) : $_[1]}; sub max {$_[0] ? ($_[0] > $_[1] ? $_[0] : $_[1]) : $_[1]}; END {foreach (sort {$a <=> $b} keys %days) {print "$_,$days{$_}{min},$days{$_}{max},".($days{$_}{sum}/$days{$_}{cnt})."\n"}}' < mawson.data


Thankfully it worked