Benjamin W. Smith

Benjamin W. Smith

Benjamin W. Smith  //  Sysadmin by trade, Pythonista by passion. Dad to two boys and a girl. Guitarist. I like my coffee black, just like my metal.

Apr 10 / 11:19pm

History meme, in Perl!

So I submitted a post to perlmonks RE: all the 'history meme' brouhaha. I provided two one liners in Perl (Below) and asked for people to improve/shorten/spice up the 'history meme' via Perl. We'll see how that goes :).

So, here's what I gave them to start with:

history | perl -le 'while($l = <>) 
{$n=${[split(/s+/,$l)]}[2];$h{$n}++;} $i=0;foreach $k 
(reverse sort {$h{$a}<=>$h{$b}} keys %h) {last if $i > 9; print "$h{$k} $k"; $i++;}'
history | perl -le 'while($l = <>) ;
{$n=${[split(/s+/,$l)]}[2];$h{$n}++;} $i=0;@a=reverse 
sort {$h{$a}<=>$h{$b}} keys %h; print "$h{$a[$_]} $a[$_]" for (0..9)'
Filed under  //  geek   history   meme   perl