Option to warn/die on fetch with invalid hash key?

[email protected] (Jim Avera)
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
Hello,

Has there been past discussion of how (or whether) to allow warn/die if 
a non-existent hash key is used for a fetch?   It would be very helpful 
if one could write something like

    use warnings 'fetch_nonexistentkey';

    sub getfoo {
       my ($self) = @_;
       return $self->{data}->{fop}
    }

...and have Perl complain immediately when non-existent key 'fop' is 
used (giving the file/linenum), rather than at best giving an 
'uninitialized' warning in far-distant code which used the value.

`no autovivification;` handles the subset of cases involving complex 
multi-level data structures.  But simple typos to constant keys 
(simulating structs) in simple data remain a source of pain.

I feel sure this has been discussed before, but I'm curious if there is 
a fundamental reason something like this could not be easily implemented.

For motivation, see 
https://stackoverflow.com/questions/3740833/how-can-i-make-perl-die-when-reading-but-not-writing-to-non-existing-keys-in-d 


If there's a thread about this I should read, please just point me to it.

Thanks,
-Jim
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.