in reply to Re: exists (EXPR), autovivified and conditionals
in thread exists (EXPR), autovivified and conditionals

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.
  • Comment on Re: Re: exists (EXPR), autovivified and conditionals