Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Newlines: reading files that were created on other platforms

by monkey_boy (Curate)
on Feb 02, 2005 at 09:32 UTC ( #427186=note: print w/ replies, xml ) Need Help??


in reply to Newlines: reading files that were created on other platforms

Hi, this works on linux & windows, not tried mac,:

open(FH,"<:crlf",$file)



I should really do something about this apathy ... but i just cant be bothered


Comment on Re: Newlines: reading files that were created on other platforms
Download Code
Re^2: Newlines: reading files that were created on other platforms
by bass_warrior (Beadle) on Feb 02, 2005 at 14:13 UTC
    Can someone explain this one a little more.
    I did a quick look in programming perl and Advanced perl programming and did not see anything like this.

    Thanks
      Hi, sorry for the terse answer!
      Its the syntax for combining this
      open(FH, "<$file"); binmode(FH, ":crlf");

      The :crlf bit just tells perl to look for varients of line-ending sequences & turn them all into "\n".
      there is more info in the Cammel book.

      Update
      In the "open" documentation, Page 754 in the 3rd edition.






      I should really do something about this apathy ... but i just cant be bothered
        Thanks, Must be time to retire my 2nd Ed. and get the 3rd.
        I also did a little more RTFM and found it in perlfunc.

        This may seem like a trivial thing to some but I always assume my input files are unix based therefore I fight this problem more often than I would like to admit.

        I've converted files using unix tools and converted lines in a sloppy way that always got the job done but seemed like more of a hack than anything. I really needed something quick (starting to sound like the usual case for me? Re: Don't go all PerlMonks on me -- leaving for a long weekend (AGAIN), in less than an hour (AGAIN)).

        This was so simply and worked with almost a simply cut/paste (I only changed the file handle). I was going to do sloppy programming (I was told to read documentation, but really wanted to test and troubleshoot if it threw an error) but this worked like a charm - clean and concise without the use of confusing regular expressions.

        Thank you so very much.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-10-22 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (114 votes), past polls