I was playing around with this and noticed a harmless but problematic side-effect of the way you construct the hash.
%scores = (
map { $_ => 1 } qw( A E I L N O R S T U ),
map { $_ => 2 } qw( B D G ),
map { $_ => 3 } qw( C M P ),
map { $_ => 4 } qw( F H V W Y ),
map { $_ => 5 } qw( K ),
map { $_ => 8 } qw( J X ),
map { $_ => 10 } qw( Q Z ),
);
print join($", sort keys %scores), $/;
__END__
10 2 3 4 5 8 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Since you're filtering for letters, the numbers don't get picked up, but the maps are having a side-effect mapping of the other maps below them. Parens around the maps seems to fix it.
I also learned something from your example. I would have predicted that the last unless defined would not work right on empty input b/c $_ still contains a "\n" which would be defined. I would have been wrong.
-
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.
|