my $analysis_file = shift; open INFILE_1, '<', $analysis_file or die "Can't open '$analysis_file': $!\n"; while(<INFILE_1>) { my $ALL_FT_FILE = $_; # or some part of $_ after munging open INFILE_2, '<', $ALL_FT_FILE or die "Can't open '$ALL_FT_FILE': $!\n"; while(<INFILE_2>) { ... # is the outer $_ clobbered here? } }
That's considerably shorter, and more to the point, isn't it?
Answer: No, each $_ is localized to its own while() block. But you can't access the contents of the outer $_ from the inner block, unless you assign that to another variable.
<update>
*Sigh*. As jdporter pointed out, yes, $_ isn't localized in a while loop:
open O, '>', 'foo'; print O "bar\n"; close O; open O, '>', 'bar'; print O "$_\n" for qw(foo quux wrdlbrmfd); close O; open I, '<', 'foo'; while (<I>) { chop; open II, '<', $_ if -f $_; while (<II>) { print; } print "\$_ = '$_'\n"; } __END__ foo quux wrdlbrmfd $_ = ''
As you see at the last line of the ouput above, $_ is clobbered.
</update>
Some nits:
</pedantic> :)
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re: risk of confusion
by shmem
in thread risk of confusion
by steph_bow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |