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

[perl #60222] changing $#array in local sub array affects global $#array

Thread Previous
From:
reneeb via RT
Date:
October 30, 2008 07:18
Subject:
[perl #60222] changing $#array in local sub array affects global $#array
Message ID:
rt-3.6.HEAD-11699-1225362168-1676.60222-15-0@perl.org
You should do

 local @f = @f;
 $f[2] = 9;
 ...

instead of 

  local @f[2] = 9;

~/perl-5.10.0 GMT $ ./perl -le'@f=(1,2,3,4);{local @f = @f;
$f[2]=9;print @f;print $#f;$#f=1;print @f;print $#f}print @f;print $#f'
1294
3
12
1
1234
3

Something related can be found here:
http://rt.perl.org/rt3/Public/Bug/Display.html?id=10041

On Do. 30. Okt. 2008, 03:02:20, thg@hafro.is wrote:
> Here is a one liner to demonstrate the bug:
> 
> perl -e'$\="\n";@f=(1,2,3,4);{local @f[2]=9;print @f;print
> $#f;$#f=1;print @f;print $#f}print @f;print $#f'
> 1294
> 3
> 12
> 1
> 123
> 2
> 
> perl -V output is in attachment.
> 
> I do not have the expertise to suggest how to fix the perl code.
> 
> Best wishes
> 
> Th.G.
> 
> 




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