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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.