http://www.perlmonks.org?node_id=153745


in reply to Re: Extreme Example of TMTOWTDI
in thread Extreme Example of TMTOWTDI

push @{$Word{length$_}},$_ while (<>);

I have to admit I don't really get that one. I'm realising there's a lot I don't know about hashes of arrays and arrays of hashes.

My preferred solution to the problem would have gone like this (pseudocode!):

$len = length($_); #let's say $len is 5 $hash{$len}=[] unless defined $hash{$len}; # make a hash key called "5" with an empty array as the value push($hash{$len},$_); #use it as an array and push this five-letter word onto it.

but, as I'm sure you all know, I couldn't do that.

Was I even close? What's the hash way to do this?

You REALLY want to run/develop code with use strict; and -w

I do most of the time, really. Honestly. No, I do. Sometimes anyway. I have got "or die $!" on my file opens at least, I'm getting better.

--

($_='jjjuuusssttt annootthhrer pppeeerrrlll haaaccckkeer')=~y/a-z//s;print;