Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: exists (EXPR), autovivified and conditionals

by barrd (Canon)
on Sep 28, 2003 at 14:53 UTC ( [id://294755]=note: print w/replies, xml ) Need Help??


in reply to exists (EXPR), autovivified and conditionals

Thanks guys,
Well that clears a few things up and I'll have to re-look into why my original code isn't working, it uses quite a few other modules so I may have inadvertently caused a third party error. Thanks again for the very prompt answers and I now have the confidence to go back and fix the problem knowing that there is a solution in there somewhere.

I always love a challenge.

Replies are listed 'Best First'.
Re: Re: exists (EXPR), autovivified and conditionals
by aquarium (Curate) on Sep 28, 2003 at 22:08 UTC
    I haven't run your example, but i can see a problem with the example code. "exists" checks for the key in the hash having been defined and pointing to a value or valid reference. Since you initialize the hash with references to the different subs, all those hash keys will exist. You should use "defined" or just a plain if(hash{key}), which does a similar thing but is more portable. Autovivified -- i had the same problem reading camel book, it assumes you know already. it means that if a variable does not exist it will spring into existence when you try to use it..the variable's value will be undefined/false until you do something to change that. Example: if(exists $hash{key}) if you don't declare/init this hash beforehand, the "exists" function will pretend the hash by that name is there. It will not crash your program, but will instead tell you if the particular key exists for this automatically created hash.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-29 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found