Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Easy hash question (uninitialized value)

by Lotus1 (Vicar)
on May 16, 2018 at 13:54 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1214657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found