Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: non-autovivifing hash

by lofichurch (Beadle)
on Jul 02, 2003 at 20:02 UTC ( #270928=note: print w/replies, xml ) Need Help??


in reply to non-autovivifing hash

Why not use exists() first, before attempting to assign the value?

Why change the underlying operation of the language, when all you have to change is your methodology?

I find it a useful practice, that whenever I expect a certain key in a certain hash, to use exists() to verify that the key exists before attempting to read its value. exists() will NOT create a key if it does not already exist. e.g.:

if( exists($hash{"$key"}) ) {
   print("You have \$hash{'$key'}\n");
   } else {
      print("You've messed up with \$hash and $key.\n");
      }

I'd absolutely hate it if anyone ever turned off the automatic creation of keys in a hash on any of my scripts.



!c

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-05-27 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (94 votes). Check out past polls.

    Notices?