going crazy here!

M

Monkey Man

Somebody tell me what's wrong with this code

#!/usr/bin/perl -w

%name = ( "ziya" => "aktas", "kimberly" => "aktas", "azer" => "apaydin" );

print "Enter Something: ";
my $key = <STDIN>;
print $name{ $key };


gives the error

Use of uninitialized value in print at ./hash.pl line 8, <STDIN> line 1.
 
B

Ben Morrow

use strict;
%name = ( "ziya" => "aktas", "kimberly" => "aktas", "azer" => "apaydin" );

^^ my
print "Enter Something: ";
my $key = <STDIN>;
print $name{ $key };

gives the error

Use of uninitialized value in print at ./hash.pl line 8, <STDIN> line 1.

$key was not any of the keys in the hash. This is probably because it
still has a newline on the end: see perldoc -f chomp.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top