Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: The Bad, the Ugly, and the Good of autovivification

by tall_man (Parson)
on Apr 08, 2005 at 05:25 UTC ( #445956=note: print w/replies, xml ) Need Help??


in reply to The Bad, the Ugly, and the Good of autovivification

I'm finding misspelled keys enough of a problem in my applications that I'm considering drastic solutions like Tie::Hash::FixedKeys for critical hashes where I know the keys in advance.
use strict; use Tie::Hash::FixedKeys; my %a : FixedKeys( qw(a b) ); %a = (a => 1, b=> 2); print "Doesn't exist\n" unless exists($a{c}); print "Also Doesn't exist\n" unless exists($a{c}->{d}); print "Oh, my, not good\n" if exists($a{c});

The attempted autovivification on line 7 will cause a croak.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://445956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2019-04-20 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I am most likely to install a new module from CPAN if:
















    Results (109 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!