develooper Front page | perl.perl5.porters | Postings from October 2007

Re: [perl #46987] OO-call failures, autoviv-functions & testing their exists" [D [D [D [D [D [D [D" l lie "exists"-ance

Thread Previous
October 29, 2007 05:46
Re: [perl #46987] OO-call failures, autoviv-functions & testing their exists" [D [D [D [D [D [D [D" l lie "exists"-ance
Message ID:
On 10/28/07, via RT Linda Walsh <> wrote:
> This is a bug report for perl from,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
>     my @dummy=(\&boom);                                         #ln 22
> The above prog demonstrates three (3) OO-call related problems.
> Perl autovivifies "\&boom" into "@dummy" in "sub laytrap" (ln 22,
> above). This *interferes* with OO calls through a blessed ref
> later on in program execution.

IMO this isnt a bug. It may be confusing behaviour, but its not a bug.
It works just the same as the equivalent code would work with a hash.

d:\>perl -e"my $x=\&foo; eval 'sub foo { warn qq(foo) }'; $x->()"
foo at (eval 1) line 1.

d:\>perl -e"my %f; my $r=\$f{x}; $$r='testing'; print $f{x};"

The similarity in behavior is not unexpected, given that Perl's global
symbol tables are really just hashes in disguise.

The code you marked as #ln 22, and quoted above is the problem.
Essentially you are creating a function stub, which perl expects you
to fill in later, but you haven't filled it in. Since this produces
undesirable results you simply shouldn't do that. You should do
something like

   my @dummy; push @dummy,(\&boom) if defined *boom{CODE};     #ln 22

which takes a reference to the sub only if it is actually defined.

With this modification I get the following output

zero:trap laid


perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About