develooper Front page | perl.perl5.porters | Postings from April 2001

Re: [ID 20010412.002] tie() magic upsets stack (can't last() outsideofblock)

Thread Previous | Thread Next
From:
Jeff Pinyan
Date:
April 12, 2001 15:27
Subject:
Re: [ID 20010412.002] tie() magic upsets stack (can't last() outsideofblock)
Message ID:
Pine.GSO.4.21.0104121826530.24596-100000@crusoe.crusoe.net
On Apr 12, Rick Delaney said:

>jpinyan@sushi.riskgrades.com wrote:
>> 
>[snip]
>> sub STORE {
>>   my ($self, $val) = @_;
>>   local $_ = $self->{VAL} = $val;
>>   $self->{CODE}->() ? $_ : last;   # <-- bad news
>> }
>[snip]
>> When I run this code, I'm told I can't call last() from outside a loop
>> block.
>
>That is only a warning.  Your code should still work as you expect.  One
>other way to suppress the warning (not mentioned on fwp) would be to put

No, that is not a warning.  A warning is when you use last() to get out of
a loop while in a subroutine.  This message is a fatal error:

  Can't "last" outside a loop block at ensure line 23.

It occurs because when Perl gets to STORE via tie() magic, it
"forgets" itself.

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734


Thread Previous | Thread Next


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