Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

quidity (1296)

quidity
  (email not shown publicly)
http://the.earth.li/~alex/
Jabber: quidity@jabber.earth.li

A relapsing reformed physicist.

Journal of quidity (1296)

Monday June 26, 2006
12:46 PM

heroic one liners

[ #30048 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.