Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 pondering the Monastery: (7)
As of 2024-03-28 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found