develooper Front page | perl.perl5.porters | Postings from December 2011

[perl #22613] for does not properly localize $\

From:
James E Keenan via RT
Date:
December 4, 2011 17:46
Subject:
[perl #22613] for does not properly localize $\
Message ID:
rt-3.6.HEAD-5084-1323049553-1130.22613-15-0@perl.org
On Sat Jun 07 13:28:55 2003, perl-5.8.0@ton.iguana.be wrote:

> 
> perl -we '$\="4\n"; for $\ (1) { print 5 }'
> 54
> 
> I expected 51
> 

Since you are attempting to use a Perl special variable ($\) as a loop
iterator variable.  You are assuming that it will be assigned to like $_.

However, 'perldoc perlsyn' warns against doing this:

#####
"foreach" probably won't do what you expect if VAR is a tied or other
 special variable.   Don't do that either.
#####

This documentation was added in 1998.  So I don't think this constitutes
a bug.

Thank you very much.
Jim Keenan



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