Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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,


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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others cooling their heels in the Monastery: (3)
    As of 2024-07-13 09:35 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      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.