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?


In reply to Re: Apparently strange beahavior that blocks at Filehandle reading by 7stud
in thread Apparently strange beahavior that blocks at Filehandle reading by NewMonkMark

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.