dbanas has asked for the wisdom of the Perl Monks concerning the following question:
When I run the code, above, I get this output: (The local directory contains 2 *.txt files: test1.txt and test2.txt.)1 #! /usr/bin/perl -w 2 3 my @test_files = glob "*.txt"; 4 5 foreach (@test_files) { 6 print "Starting processing of file, $_.\n"; 7 open TEST_FILE, "< $_" or die "Couldn't open test file, '${_ +}', for reading: ($!)"; 8 9 while (<TEST_FILE>) { 10 print; 11 } 12 13 print "Ending processing of file, $_.\n"; 14 }
Note the missing filenames at the ends of both "Ending processing..." lines, as well as the warnings immediately preceeding them. Here are the contents of "test1.txt" and "test2.txt":Starting processing of file, test1.txt. Line 1 from 'test1.txt' Line 2 from 'test1.txt' Line 3 from 'test1.txt' Use of uninitialized value in concatenation (.) or string at ./test.pl + line 13, <TEST_FILE> line 3. Ending processing of file, . Starting processing of file, test2.txt. Line 1 from 'test2.txt' Line 2 from 'test2.txt' Line 3 from 'test2.txt' Use of uninitialized value in concatenation (.) or string at ./test.pl + line 13, <TEST_FILE> line 6. Ending processing of file, .
test2.txt:Line 1 from 'test1.txt' Line 2 from 'test1.txt' Line 3 from 'test1.txt'
Line 1 from 'test2.txt' Line 2 from 'test2.txt' Line 3 from 'test2.txt'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $_ getting clobbered by inner loop.
by pc88mxer (Vicar) on Apr 08, 2008 at 23:49 UTC | |
|
Re: $_ getting clobbered by inner loop.
by bigmacbear (Monk) on Apr 08, 2008 at 23:57 UTC | |
|
Re: $_ getting clobbered by inner loop.
by ysth (Canon) on Apr 09, 2008 at 03:16 UTC | |
|
Re: $_ getting clobbered by inner loop.
by GrandFather (Saint) on Apr 09, 2008 at 00:24 UTC | |
|
Re: $_ getting clobbered by inner loop.
by lestrrat (Deacon) on Apr 08, 2008 at 23:50 UTC | |
|
Re: $_ getting clobbered by inner loop.
by ikegami (Patriarch) on Apr 09, 2008 at 00:48 UTC | |
by dbanas (Novice) on Apr 09, 2008 at 14:34 UTC | |
by SuicideJunkie (Vicar) on Apr 09, 2008 at 17:59 UTC | |
by ikegami (Patriarch) on Apr 10, 2008 at 00:04 UTC | |
by Anonymous Monk on Apr 09, 2008 at 14:37 UTC |