dlal66 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am experiencing the strangest possible issue and have no ideas left anymore. Any help is appreciated. I am essentially reading 3 types of text files from a directory, parsing them using Text::CSV and then writing them to an Excel file using Excel::Writer. All was working well. Then I decided to copy on of the text files (p220-816867-052_avl.txt) to the same directory under a different name (p220-816867-053_avl.txt). The code reads each file in sequence. Now what is happening is that after processing the original files with success, when the code comes to process p220-816867-053_avl.txt, the (while my $line = <FILE>) is reading the whole file in one line and this skipping all newlines in the file. I spent hours trying to figure out but to no avail. I checked and the file p220-816867-053_avl.txt does have 80 lines. It is the same file as the original that I copied from. But the while command is reading the whole file in one line? Any ideas and thanks in advance

Replies are listed 'Best First'.
Re: Issue with read a file
by marinersk (Priest) on Sep 12, 2013 at 16:34 UTC
    Would love to help.

    Need to see some kind of code to even have a decent guess.

    So, my random thought for the day: Is there any chance you are forgetting to close the file(s) after you read it/them and Perl is getting confused in some way?

    Otherwise, will need to see something. Can't imagine what you've done wrong if we don't know what you've done.

      I understand..thanks. I found the issue but I still do not have a solution. When reading the text files, one of the file I read in a string (by setting undef $/). Therefore when I go the next file and want to read it line by line, I am getting the issue. Now I am doing a $/='\n'; before I read the next file line by line. But this is not helping. The file is being read in one line. Any clues why? Thanks
        Use double quotes. Single quotes do not interpolate. Or even better, set $/ locally.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ