[londonperl] Re: disable auto-instantiation or warn about it

David Alban extasia at extasia.org
Fri Jul 13 20:52:34 BST 2007


Nevermind.  The probability of finding the bug in your code is
directly proportional to the number of folks to whom you just sent it.

The arg to ref() should have been the same as the arg to exists().  In
which case, ref() does indeed cause $$h{ foo } to be autovified:

  $VAR1 = undef;
  after ref(): $VAR1 = {
            'foo' => {}
          };
  after exists(): $VAR1 = {
            'foo' => {}
          };

My only defense is that the output I sent was the true output of the
(buggy) code I sent.  I'll go back a re-read the tutorial.

<sigh>

On 7/13/07, David Alban <extasia at extasia.org> wrote:
>   #!/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' => {}
>           };

-- 
Live in a world of your own, but always welcome visitors.


More information about the london.pm mailing list