Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 goofing around in the Monastery: (4)
As of 2024-04-19 16:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found