http://www.perlmonks.org?node_id=946394


in reply to Re^6: Listing of files using glob
in thread Listing of files using glob

> Any errors or wrong approach??

Yep. You never chomp the data read from the filehandle FILE. Since you are building the file name directly from the line read, it most likely contains a newline. If you print your value for $line with a delimiter surrounding it (print "'$line'\n";) you will see what I mean. See chomp (as has been previously mentioned) for a solution.

Update: Since the OP is using $& to populate the hash, and the processing loop uses the keys of the hash as the name of the file, the newline from the file should not be included in the hash key. Nice catch choroba

I wonder what the line endings are in the data file. Is it possible that the file is in DOS line ending format? In which case, the chomp (and $&?) would not do the right thing.

--MidLifeXis