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.

  • Comment on Re: exists (EXPR), autovivified and conditionals

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.