The exists check works on the last part of the data structure and not each step through the data structure. Meaning:my %hash = ( a => { ab => { ac => 'yup', }, }, ); # Check for existence if (exists $hash{aa}->{ab}->{ac}) { ## Notice that 'aa' is a typo an doesn't exist ## but will be auto-created and now contain a ## hash ref with one entry 'ab'. print "ac exists.\n"; ## won't get printed } if (exists $hash{aa}) { ## This will succeed because $hash{aa} was auto ## created above. print "aa exists.\n"; ## will get printed }
Everything before that last part of the data structure gets auto created if it doesn't exist. Only the last part will not. Just keep that in mind. -spencerif exists $hash{aa} ## exists doesn't check this ->{ab} ## Nor this ->{ac} ## Ah ha! exists does check here ;
In reply to Re: checking if hashref value exists based on a dynamic array
by localfilmmaker
in thread checking if hashref value exists based on a dynamic array
by jonathan415
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |