Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Easy hash question (uninitialized value)

by Lotus1 (Priest)
on May 16, 2018 at 13:54 UTC ( #1214657=note: print w/replies, xml ) Need Help??


in reply to Easy hash question (uninitialized value)

Also check out the function exists. It lets you test if a key is in a hash. In this case it would help you debug but it's useful in general for validating hash keys, especially when they come from user input.

I added the following at the end of your script:

if( exists $j{$number} ) { say $j{$number}; say "done"; } else { say "<$number> is not a key in \%j" }

Here is the result of running it:

C:\usr\pm\hash>perl 1214633.pl 4 4 <4 > is not a key in %j

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-11-13 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (149 votes). Check out past polls.

    Notices?