Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Printing a String (TOO stupid?)

by TGI (Parson)
on Jun 20, 2014 at 05:06 UTC ( #1090550=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090550]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2020-10-24 09:14 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (242 votes). Check out past polls.