Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Homework help

by Your Mother (Archbishop)
on Oct 30, 2004 at 07:04 UTC ( #403979=note: print w/replies, xml ) Need Help??


in reply to Re: Homework help
in thread Homework help

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.

Replies are listed 'Best First'.
Re^3: Homework help
by ikegami (Patriarch) on Oct 30, 2004 at 17:55 UTC
    I would have predicted that the last unless defined would not work right on empty input b/c $_ still contains a "\n"
    It doesn't work on empty input. It works on eof/error. It's there to prevent the next two lines from giving "undefined value" warnings under use warnings. The last unless length that follows is what detects the empty string (since chomp removed the "\n" by then).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://403979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2023-09-28 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?