in reply to Re: gotchas with hash element autovivification
in thread gotchas with hash element autovivification
if ($rec{NOTE} && exists $rec{NOTE}{Nested}) {
More-DRY versions:
if( exists ${ $rec{NOTE} || {} }{Nested} ) { # or if( ( $rec{NOTE} || {} )->{Nested} ) { # or if( exist +( $rec{NOTE} || {} )->{Nested} ) {
Though, I find that I use those less often to avoid auto-viv and more often to prevent a potential fatal "Can't use undef as HASH ref" (something that I think should at least be turned into just a warning -- since sometimes it is fatal and sometimes it is a silent success, and I'm not even sure what distinguishes between those two behaviors).
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: gotchas with hash element autovivification (dry)
by JavaFan (Canon) on Apr 03, 2012 at 06:22 UTC |