CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with hashes

 



aiikahn
Novice

Feb 22, 2008, 10:40 PM

Post #1 of 4 (334 views)
Help with hashes Can't Post

I'm fairly new with Perl and I was wondering if anyone could tell me why my code isn't working below. I'm trying to print the value when the key is entered via user input. Here's the code below:

%hash = (1,'Fred' , 2, 'Flintstone', 3, 'Barney', 4, 'Rubble');
print "Number: ";
$number = <STDIN>;
print $hash{$number};

When I run the program, it only gives me a blank line. I'd greatly appreciate any help. Thank you.

-AR


KevinR
Veteran


Feb 22, 2008, 10:45 PM

Post #2 of 4 (333 views)
Re: [aiikahn] Help with hashes [In reply to] Can't Post


Code
%hash = (1,'Fred' , 2, 'Flintstone', 3, 'Barney', 4, 'Rubble'); 
print "Number: ";
chomp($number = <STDIN>);
print $hash{$number};

-------------------------------------------------


aiikahn
Novice

Feb 22, 2008, 11:08 PM

Post #3 of 4 (331 views)
Re: [KevinR] Help with hashes [In reply to] Can't Post

Wow...thank you so much for your time. I feel so dumb now...thanks again!


KevinR
Veteran


Feb 22, 2008, 11:12 PM

Post #4 of 4 (330 views)
Re: [aiikahn] Help with hashes [In reply to] Can't Post

You're welcome
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives