As mentioned by Anonymous Monk above, has an autovivification module for those (rare) occasions when you don’t want it to occur:
#! perl use strict; use warnings; print "\nWITH autovivification:\n"; my $hashref1; printf "1. \$hashref1 %s defined\n", (defined $hashref1 ? 'IS' : 'is N +OT'); my $foo = $hashref1->{bar}; printf "2. \$hashref1 %s defined\n", (defined $hashref1 ? 'IS' : 'is N +OT'); no autovivification; print "\nWITHOUT autovivification:\n"; my $hashref2; printf "3. \$hashref2 %s defined\n", (defined $hashref2 ? 'IS' : 'is N +OT'); my $baz = $hashref2->{bar}; printf "4. \$hashref2 %s defined\n", (defined $hashref2 ? 'IS' : 'is N +OT');
Output:
0:43 >perl 830_SoPW.pl WITH autovivification: 1. $hashref1 is NOT defined 2. $hashref1 IS defined WITHOUT autovivification: 3. $hashref2 is NOT defined 4. $hashref2 is NOT defined 0:43 >
This may (occasionally) be a handy tool to have in the toolbox.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Autovivification in perl
by Athanasius
in thread Autovivification in perl
by rammohan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |