in reply to Re^2: iterative foreach loop
in thread iterative foreach loop

That's fine, subject to the hints haukex provided.

Now that you understand the diamond operator (perlop: IO Operators) you can use a modern tool to do the busywork of opening and closing files, character encoding, removing new line characters, error handling, etc.

use strict; use warnings; use feature 'say'; use Path::Tiny; # imports path() my $filename = '/TEXT2.txt'; say for path( $filename )->lines_utf8({ chomp => 1 }); __END__

See also:

Hope this helps!


The way forward always starts with a minimal test.