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
From:
demerphq
Date:
October 29, 2007 05:46
Subject:
Re: [perl #46987] OO-call failures, autoviv-functions & testing their exists" [D [D [D [D [D [D [D" l lie "exists"-ance
Message ID:
9b18b3110710290546u55e187a8qe4cfa8028a0d539@mail.gmail.com
On 10/28/07, via RT Linda Walsh <perlbug-followup@perl.org> wrote:
> This is a bug report for perl from perl-diddler@tlinx.org,
> 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};"
testing

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

two
one
zero:trap laid
unprint
unprint

HTH,
Yves


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

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About