On Wed, Jun 15, 2005 at 11:38:36AM +0100, [EMAIL PROTECTED] wrote:
> :--- ./t/op/local.t   Mon Jun 13 20:18:48 2005
> :+++ ./t/op/local.t   Mon Jun 13 20:26:54 2005
> :@@ -268,8 +268,9 @@ eval { for ($1) { local $_ = 1 } };
> : print "not " if $@ !~ /Modification of a read-only value attempted/;
> : print "ok 77\n";
> : 
> :+# make sure $1 is still read-only
> : eval { for ($1) { local $_ = 1 } };
> :-print "not " if $@;
> :+print "not " if $@ !~ /Modification of a read-only value attempted/;
> : print "ok 78\n";
> 
> I may be misreading it, but I think here the C< local $_ > retains
> the $1 magicalness because it is container magic?

If I supply more context for that chunk:


    --- ../24825.ORIG/t/op/local.t      2005-06-13 20:18:48.000000000 +0100
    +++ t/op/local.t    2005-06-13 20:26:54.000000000 +0100
    @@ -266,12 +266,13 @@
     
     eval { for ($1) { local $_ = 1 } };
     print "not " if $@ !~ /Modification of a read-only value attempted/;
     print "ok 77\n";
     
    +# make sure $1 is still read-only
     eval { for ($1) { local $_ = 1 } };
    -print "not " if $@;
    +print "not " if $@ !~ /Modification of a read-only value attempted/;
     print "ok 78\n";
 
you'll see that the original local.t performed the *same* test twice, and
expected *different* results the second time round (this was a bug in
local.t as well as a bug in perl). My patch makes the behaviour consistent
across multiple executions of the same code. The behaviour of allowing you
to localize $1 while preserving read-onlyness, even if via a $_ alias, is
unchanged by my patch.

> If so, that's a shame - we should really be able to use C< local $_ >
> to get an unadorned scalar: the sledgehammer C< local *_ > is no
> substitute for that.

The trouble is that for some types of magic, eg %ENV, people have a strong
expectation that localising preseves magic, ie local %ENV = qw(foo bar)
temporarily wipes all old env vars and gives you a single new one.  Given
that perl can't always know when something is an alias, you get things
like

    *env2 = \%ENV;
    local %env2 = ...;

where perl still needs to copy the magic to the local hash.

-- 
The Enterprise is involved in a bizarre time-warp experience which is in
some way unconnected with the Late 20th Century.
    -- Things That Never Happen in "Star Trek" #14

Reply via email to