in reply to Re: How to open file inside loops with file names generated using an array?
in thread How to open file inside loops with file names generated using an array?

I have tried that. The file names are printing properly. The variables themselves independently also looks fine when printed. Also I can open these files when I loop them directly using the array like.
open ( TEST, ">", "test.txt") or die "\n$!\n"; foreach my $var ( @file_list ) { print "\n$var\n"; open ( RL, "<", $var ) or die "\n$!\n"; while (<RL>){ print TEST $_; } }
  • Comment on Re^2: How to open file inside loops with file names generated using an array?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to open file inside loops with file names generated using an array?
by roboticus (Chancellor) on May 28, 2018 at 12:50 UTC

    skooma:

    You missed one bit that choroba put in his code: He wrapped the filename in brockets (<>) so that whitespace at the beginning or ending of the line would be more obvious. I expect that he's thinking your code would print something like:

    <foo >

    instead of the expected:

    <foo>

    because you may have gotten your data from a file without remembering to chomp off the line endings.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.