I\'m on break from classes right now and decided to spend my time learning Perl. I\'m working with Beginning Perl (http://www.perl.org/books/beginning-perl/) and I\'m finish
Though it may be obvious, it's still worth mentioning why the chomp is needed here.
The hash created contains 4 lookup keys: "Me"
, "Home"
, "Emergency"
and "Lookup"
When $input
is specified from
, it'll contain "Me\n"
, "Me\r\n"
or some other line-ending variant depending on what operating system is being used.
The uninitialized value error comes about because the "Me\n"
key does not exist in the hash. And this is why the chomp
is needed:
my $input = ; # "Me\n" --> Key DNE, $name_number{$input} not defined
chomp $input; # "Me" --> Key exists, $name_number{$input} defined