in reply to Re: Printing a String (TOO stupid?)
in thread Printing a String (TOO stupid?)

... a problem with Windows files used under Unix ...

If this is certain to be the situation, I think I would take the approach of local-ly changing  $/ (see perlvar) to  "\x0d\x0a" to control both the reading of Windoze-ish lines from a filehandle and the behavior of chomp in removing their line-enders. Something like:

open my $fh ... or die ...; ... { local $/ = "\x0d\x0a"; while (defined(my $line = <$fh>)) { chomp $line; do_something_with($line); } }
Both problems handled in one swell foop. (Of course, you have to be aware that the change to the global  $/ propagates 'into' the  do_something_with() call and into anything that function may call, but that's a post for another day.)

Replies are listed 'Best First'.
Re^3: Printing a String (TOO stupid?)
by Laurent_R (Canon) on Jun 19, 2014 at 18:00 UTC
    Yes, that's another interesting way to do it. As for whether it is certain that it is a problem with Windows files used under Unix, I of course cannot be sure without having seen the file itself, but I know for a fact that I have met that problem a few times and got exactly the same symptoms: the words added to the end of the lines were coming over the start of the lines. And it took me at least an hour to figure out what the issue was the first time I got it.