in reply to Strange read file behaviour

Your file most likely has Windows line endings, i.e. \r\n.  When you read the file on Linux, the crlf PerlIO layer which translates \r\n to \n is not in effect by default, as it is on Windows (so the \r remains), and chomp only removes what is in $/, i.e. \n.

(\r positions the terminal's cursor to the beginning of the line, so subsequent text overwrites whatever had been written there before...)

Fix:

open DIRECTORIES, "<:crlf", $source or die $!; ^^^^

Replies are listed 'Best First'.
Re^3: Strange read file behaviour
by saintex (Scribe) on Jun 28, 2010 at 12:10 UTC
    Thank you all for reply.
    open DIRECTORIES, "<:crlf", $source or die $!;
    solved the problem.
    In effect I'm testing a cross platform code.
      Alternative:
      open DIRECTORIES, "<", $source or die $!; while (<DIRECTORIES>) { s/\s+\z//; # Remove trailing whitespace, incl \r and \n ... }