On Thu Apr 10 06:41:40 2008, eda@waniasset.com wrote: > This is a bug report for perl from eda@waniasset.com, > generated with the help of perlbug 1.36 running under perl 5.10.0. > > > ----------------------------------------------------------------- > [Please enter your report here] > > This is an enhancement request for a small change to the perl > language. A 'foreach (1, 2, 3) {}' loop implicitly localizes $_ but a > 'while (<$fh>)' does not. I suggest changing the semantics of 'while > (<$fh>)' so it does the same localization, or if this is too much to > stomach, adding a warning if the 'while (<$fh>)' construct is used in > a subroutine without localizing $_ first. > > #!/usr/bin/perl > use warnings; > use strict; > use 5.010; > $_ = 'x'; > open FH, '<', '/dev/null' or die; > while (<FH>) {} > say defined($_) ? "defined: $_" : 'not defined'; > $_ = 'y'; > foreach (1, 2, 3) {} > say defined($_) ? "defined: $_" : 'not defined'; > > This shows that a while-loop doesn't localize $_ but a foreach-loop > does. This is the documented behaviour, so this is not a bug. It > might be worth changing it for perl 5.12. > > sub my_sub { > open my $fh, '<', 'some_file' or die; > while (<$fh>) { say 'hi' } > } > > This code doesn't produce a warning on current perl, but I think it > should say > > warning: while (<filehandle>) implicitly sets $_, but it is not > localized first in subroutine my_sub > > or some similar warning. > List: This request for a change in Perl's behavior was made several years ago but didn't garner any support. Can we close the ticket now? Thank you very much. Jim Keenan --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=52702Thread Next