develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991114.001] dangerous behavior from local

Thread Previous
From:
Ronald J Kimball
Date:
November 15, 1999 19:10
Subject:
Re: [ID 19991114.001] dangerous behavior from local
Message ID:
19991115220959.C571837@linguist.dartmouth.edu
On Mon, Nov 15, 1999 at 07:01:44PM -0800, Tom Phoenix wrote:
> On Sun, 14 Nov 1999, Andrew Pimlott wrote:
> 
> > A coworker accidentally did:
> > 
> > {
> >     local($/ = undef);
> >     ...
> > }
> > 
> > This did not localize $/ .  I don't know what it did do.
> 
> It looks to me as if it did localize $/ -- but only _after_ storing undef
> into it. Oops!
> 

That was my guess, too, but further tests don't seem to be consistent with
that conclusion:

#!perl -w

$x = 'a';

print "1: $x\n";

{
  local($x = undef);
  print "2: $x\n";
  $x = 'b';
  print "3: $x\n";
}

print "4: $x\n";

---

1: a
Use of uninitialized value at foo line 9.
2:
3: b
4: b

--

If $x were being localized at all, then 4 would be 'a', rather than 'b'.


Ronald

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