Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: non-autovivifing hash

by lofichurch (Beadle)
on Jul 02, 2003 at 20:02 UTC ( [id://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.


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-05-25 18:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found