Related nodes:

I primarily work in a linux server environment. I often encounter files that were originally written on another operating system. That can make life hard for scripts like the following:

$ echo -e "123\n456\n789" > foo.txt $ hexdump -C foo.txt 00000000 31 32 33 0a 34 35 36 0a 37 38 39 0a |123.456.7 +89.| 0000000c $ cat foo.txt | perl -wle 'use strict; while(my $line = <>) { chomp $l +ine; ($line =~ m/^\d+$/) ? print qq{number ok:"$line"} : print qq{num +ber error:"$line"} }' number ok:"123" number ok:"456" number ok:"789" $ unix2dos foo.txt unix2dos: converting file foo.txt to DOS format ... $ hexdump -C foo.txt 00000000 31 32 33 0d 0a 34 35 36 0d 0a 37 38 39 0d 0a |123..456. +.789..| 0000000f $ cat foo.txt | perl -wle 'use strict; while(my $line = <>) { chomp $l +ine; ($line =~ m/^\d+$/) ? print qq{number ok:"$line"} : print qq{num +ber error:"$line"} }' "umber error:"123 "umber error:"456 "umber error:"789 $
I'd like my scripts to be platform-agnotic, that is, process files regardless of being created on a Unix, Windows or Mac platform.

I use unix2dos manually on occations, but I'd rather have my perl scripts do this themselves when they encounter files created on a foreign operating system. Is there a reliable way to do this?

--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

In reply to Process file regardless of the platform it was created on by andreas1234567

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.