Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-12-08 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (36 votes). Check out past polls.

    Notices?