disable auto-instantiation or warn about it

Nic Gibson nicg at noslogan.org
Fri Jul 13 16:53:26 BST 2007


On 13/07/07, Jonathan Stowe <jns at gellyfish.com> wrote:
> On Fri, 2007-07-13 at 15:54 +0100, Frank v Waveren wrote:
> > Lectori Salutem (or, if you prefer, "Hello"),
> >
> > I'm going to veer dangerously on-topic here and ask a perl question
>
> ITYM "off-topic"
>
> > that's been bothering me for some time:
> >
> > Is there any way to turn off auto-instantiation, or at least to make
> > perl emit a warning when it happens?
> >
> > The auto-instantiation I mean here is the kind that makes evaluating
> > "$foo->{bar}" turn $foo into a hashref if it's undef. It's a nice
> > feature in some cases, but especially in larger projects it's a huge
> > source of bugs, in my experience.
> >
>
> It's generally called auto-vivification. However you want to "use
> strict" that will stop that particular class of bug.

Um, no it doesn't...

use strict;
my $foo = undef;
my $n = $foo->{bar};
print ref($foo), "\n";

happily prints out "HASH"

I would like to know if there is an answer to that tho.

nic

(assuming I understood the original question correctly)

-- 
Nic Gibson
Director, Corbas Consulting Ltd
Editorial and Technical Consultancy
http://www.corbas.co.uk/


More information about the london.pm mailing list