in reply to $_ getting clobbered by inner loop.
The default loop variable $_ is only meant to be used for small code fragments. For anything more complicated you should use a named lexical.for my $file (@test_files) { # use $file here while (<TEST_FILE>) { # use $_ here } }
Update: Your example does illustrate the difference between for loops and while loops. In the following nested loops, $_ does not get clobbered:
for (1..3) { print "_ before = $_\n"; for ('a'..'c') { print "_ inner loop = $_\n"; } print "_ after = $_\n"; # prints same as before inner loop }
|
|---|