Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm not quite sure what behavior you're trying to get out of this. ASCII (text) files are, by their very nature, different than binary files not only in that they tend to contain only readable data, but this data is broken up into multiple lines. Each OS handles newlines differently, as I'm sure you know. Tools written for one OS should (for major compatibility reasons) adapt to that OS's mechanism for interpreting newlines (as Perl does with \n). If you are using tools under Windows that work with text files yet do not honor Windows' newline convention, I would consider that a bug with the tools.

Along the same line, if you FTP files from one OS to another, you do so using the ASCII protocol, which correctly adapts your text file's newlines to match the conventions of the other OS, so that tools on the new OS can correctly read the lines of your file. Again, if the new OS incorrectly uses conventions from your source OS instead of the newline conventions of the OS they're running on, that is anomalous behavior that should be corrected.

If you truly need Perl to treat a file as anything but a simple text file (allowing you to set your own newline conventions), you should use binmode and treat the file as a binary file:

binmode(FH); local $/ = "\cM\cJ"; # CRLF print FH "A line of pseudo-ASCII text$/"; while (<FH>) { # This might actually work, given that it honors $/ }
If you do something like this, avoid \n, which literally means "newline", which will behave differently under different operating systems, counter to what you seem to want.

In reply to Re: How to control UNIX vs DOS line feeds in Perl by Fastolfe
in thread How to control UNIX vs DOS line feeds in Perl by thoglette

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 examining the Monastery: (3)
As of 2024-04-19 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found