JustLikeThat has asked for the wisdom of the Perl Monks concerning the following question:
I am using Visual Studio (with the Perl mod from activestate) to write this code to work in windows.
The following code is a piece of a larger program. I want to ask the user for a number and use that as the key to pull a value out of the hash. But I have not been successful. Her is the code below:
The strange thing is when I set $a to a value in the code (ie $a=5 instead of <STDIN>) I get the correct answer. Any ideas?!! And thanks in advance for your help!!#!/usr/bin/perl print "Give me a number for the tile and I will tell you the color\n"; $a=<STDIN>; print $a."\n"; %Number = qw(1 Red 2 Yellow 3 Green 4 Black 5 Purple 6 Pink 7 Brown 8 Blue 9 Orange); print $Number{$a}."\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Selecting a specific hash key to find a value
by zejames (Hermit) on Sep 23, 2004 at 16:57 UTC | |
|
Re: Selecting a specific hash key to find a value
by Sidhekin (Priest) on Sep 23, 2004 at 17:02 UTC | |
|
Re: Selecting a specific hash key to find a value
by Eimi Metamorphoumai (Deacon) on Sep 23, 2004 at 17:04 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |