[londonperl] Re: disable auto-instantiation or warn about it
David Alban
extasia at extasia.org
Fri Jul 13 20:48:31 BST 2007
Very cool! Interesting use of ref() in place of exists().
Inspired by that:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $h;
print Dumper $h;
ref $$h{ foo } eq 'HASH' and print "\$\$h{ foo } is a HASH reference\n";
print 'after ref(): ', Dumper $h;
exists $$h{ foo }{ bar } and print "\$\$h{ foo }{ bar } exists\n";
print 'after exists(): ', Dumper $h;
Output:
$VAR1 = undef;
after ref(): $VAR1 = {};
after exists(): $VAR1 = {
'foo' => {}
};
While ref() didn't cause autovivification of $$h{ foo }, it did cause
$h to become a reference to an anonymous hash.
I can live with that.
On 7/13/07, Uri Guttman <uri at stemsystems.com> wrote:
> and i wrote a tutorial about autoviv a while back that many have found
> useful.
>
> http://sysarch.com/Perl/autoviv.txt
>
> it even has a exists replacement sub that won't autovivify.
--
Live in a world of your own, but always welcome visitors.
More information about the london.pm
mailing list