http://qs321.pair.com?node_id=1090550


in reply to Printing a String (TOO stupid?)

Printing is a red-herring here. The real issue is how you open the file.

Instead of doing a plain-vanilla open, you want to turn on one of [Perl's amazing IO layers]. In this case :crlf.

open my $fh, '<:crlf', "test.txt" or die "Failed to open $!\n"; my $line; while ($line = <$fh>) { chomp($line); print "It was $line!!!\n"; }

The awesome thing about this method, is you automatically translate \r\n to \n, but if the file has plain old \n line endings, the just cruise on through to your code without a problem.

You may also notice that I used a 3-argument open with a lexical file handle. This is generally considered to be a good idea.


TGI says moo