in reply to Apparently strange beahavior that blocks at Filehandle reading
I checked the rest of the program for some strange interaction with that file and filehandle name
That's why you don't use bareword filehandles.
use strict; use warnings; use 5.010; #Create some text files: my @fnames = ('test1.txt', 'test2.txt'); for my $fname(@fnames) { open my $OUT, '>', $fname or die "Couldn't open $fname: $!"; for my $num (1 .. 10) { say $OUT "$fname -- $num"; } } #------------------ sub print_error { say 'error'; } #------------------ #Read the text files: FOR: for my $fname('test1.txt', 'test2.txt') { open my $INPUT, '<', $fname or print_error(); while(my $line = <$INPUT>) { print $line; } print "\n"; } --output:-- test1.txt -- 1 test1.txt -- 2 test1.txt -- 3 test1.txt -- 4 test1.txt -- 5 test1.txt -- 6 test1.txt -- 7 test1.txt -- 8 test1.txt -- 9 test1.txt -- 10 test2.txt -- 1 test2.txt -- 2 test2.txt -- 3 test2.txt -- 4 test2.txt -- 5 test2.txt -- 6 test2.txt -- 7 test2.txt -- 8 test2.txt -- 9 test2.txt -- 10
When the input line operator, <>, reads end-of-file, it returns a false value that causes the while loop to end.
How about using the 3-arg form of open()?
open(DB,"<$F") #compare to: open my $INFILE, '<', $fname or die "Couldn't open $fname: $!"
How about printing out the filename in the loop?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Apparently strange beahavior that blocks at Filehandle reading
by NewMonkMark (Initiate) on Jun 17, 2011 at 09:45 UTC | |
by BrowserUk (Patriarch) on Jun 17, 2011 at 09:52 UTC | |
by NewMonkMark (Initiate) on Jun 17, 2011 at 13:28 UTC | |
by BrowserUk (Patriarch) on Jun 17, 2011 at 14:15 UTC |