Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The requirements implied in your question are slightly unclear.
I need to process a text file but cannot be sure ahead of time if it's a DOS file (\r\n) or a Unix file (\n).
What platform is your script running on, and how is it getting access to the file?

If the file is a native file, "\n" will be the line terminator. If the file is being accessed over NFS or Samba, this software performs mapping of line terminators if the mount has been set up correctly.

However, there are instances when the file has been transferred by some other means, and you want to respect the termination. See perldoc perlvar on $INPUT_RECORD_SEPARATOR, $/, for how to change the default action of the <> operator, and what kind of a newline it is expecting.

Hope this helps,

--rW

Update: Just thought of a few other tips given what you are trying to do. You probably want to consider the output side as well, i.e. $OUTPUT_RECORD_SEPARATOR, $\. You might need a binmode on the file.

The last time I was doing something similar, I found perldoc perlport invaluable.


In reply to Re: Line endedness by rinceWind
in thread Line endedness by mobiGeek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-06-20 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.