Hi all

On Windows the line terminator is the two charcter sequence \x0d \x0a. On UNIX the line terminator is the single character \x0a.

If you are processing a file and you do not use binmode on the file handle, then Perl automatically uses and recognizes the native line terminator for your platform \x0d \x0a on Windows, \x0a on UNIX. Thus, $x = <FILE_IN>; will result in the last character sequence in $x being \x0d \x0a on a Windows platform and \x0 on a UNIX platform. Likewise, print FILE_OUT "Hello.\n"; will result in H e l l o . \x0d \x0a being written to the output file on Windows and H e l l o . \x0a on UNIX.

In my Perl script I allow the user to specify which line terminator to use on the command-line so that the user can get either a file with Windows line terminators or a file winth UNIX line terminators regardless of what platform the user is running on. I am doing this because we are generating data files and I need the right line terminator in the data file and the right line terminator in this specific case is not necessarily the platform native one.

I want to default to the platform native line terminator if the user does not specify a line terminator. However, I am using binmode on my file handle so on Windows Perl won't automatically translate \n to \x0d \x0a.

What I want to know is, does Perl store the native line terminator character in a special global variable? If so which one?

Can some one tell me how I can find out dynamically at run time what the native line terminator is for the platform on which my script is running?

Thanks, Regards

Peter Jirak

jira0004@yahoo.com

In reply to Is there a variable in which Perl stores the native file delimiter for the platform on which your script is running? by jira0004

Title:
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, details, 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, summary, 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.