Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Conversion of unix LF to DOS LF issues

by ikegami (Patriarch)
on Feb 01, 2006 at 23:26 UTC ( [id://527192]=note: print w/replies, xml ) Need Help??


in reply to Conversion of unix LF to DOS LF issues

You didn't specify on which system the script is running.

  • # Outputs file in DOS format. # Accepts input files in unix format. # Runs on DOS. { my $fh_in = upload('filepath'); open my $fh_out, ...; print $fh_out while <$fh_in>; }
  • # Outputs file in DOS format. # Accepts input files in unix format. # Runs on unix. { my $fh_in = upload('filepath'); open my $fh_out, ...; while (<$fh_in>) { chomp; print $fh_out "$_\r\n" } }

As a bonus, here are more universal versions:

  • # Outputs file in DOS format. # Accepts input files in unix, DOS and Mac formats. # Runs on unix, DOS and Mac. my $text; { my $fh_in = upload('filepath'); binmode($fh_in); local $/; $text = <$fh_in>; } $text =~ s/\015\012?|\012/\015\012/g; { open my $fh_out, ...; binmode($fh_out); print $fh_out $text; }
  • # Outputs file in local format. # Accepts input files in unix, DOS and Mac formats. # Runs on unix, DOS and Mac. my $text; { my $fh_in = upload('filepath'); binmode($fh_in); local $/; $text = <$fh_in>; } $text =~ s/\015\012?|\012/\n/g; { open my $fh_out, ...; print $fh_out $text; }

Update: Cleaned up my booboos.

Replies are listed 'Best First'.
Re^2: Conversion of unix LF to DOS LF issues
by master_son (Acolyte) on Feb 02, 2006 at 15:19 UTC
    The first Bonus option worked for me. I tested it on the W2003 system and everything clicked. Thank you.
    ---------------------
    Keep your concentration here and now where it belongs - Qui-Gon Jinn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2025-04-20 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.