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

[perl #119683] $! localisation broken by ref

Thread Previous
From:
Father Chrysostomos via RT
Date:
October 27, 2013 12:36
Subject:
[perl #119683] $! localisation broken by ref
Message ID:
rt-4.0.18-14229-1382877380-1762.119683-15-0@perl.org
On Sun Oct 27 00:22:32 2013, nicholas wrote:
> On Sat, Oct 26, 2013 at 01:16:54AM -0700, Father Chrysostomos via RT
> wrote:
> > 3) Separately store the actual value to be restored on the savestack,
> > in addition to the old magical scalar.
> >
> > #3 is the easiest to implement, and probably the safest in terms of
> > backward compatibility.
> 
> Wouldn't that change the behaviour of code which is able to access the
> localised variable by another route? eg this code would end up
> printing
> 5, 6, 5 not what we have currently:
> 
> $ cat /tmp/local.pl
> #!/usr/bin/perl -w
> use strict;
> 
> $::var = 5;
> 
> print "Before: $::var\n";
> foo (\$::var);
> print "After: $::var\n";
> 
> sub foo {
>     local $::var;
>     $::var = 6;
>     ${$_[0]} = 7;
>     print "During: $::var\n";
> }
> __END__
> $ perl /tmp/local.pl
> Before: 5
> During: 6
> After: 7

Yes, it would change that behaviour.  Scratch #3 then.

You see why nobody wants to fix this? :-)

> (I haven't thought very hard about this, but the whole thing does seem
> to be
> a tricky problem. I'm not sure if the underlying mess is that for
> magic
> variables that proxy through to some other storage, Perl's local isn't
> localising that underlying storage)

I think that is the underlying problem.  But how do you fix that for ties?  I.e., how do we make your example work with Tie::StdScalar?  Do we need to introduce LOCAL and UNWIND methods for ties?

Currently with $::var tied to Tie::StdScalar, it prints:

Before: 5
During: 7
After: 7

And with $! it prints the same, if you print 0+$!.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=119683

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