Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Conversion of unix LF to DOS LF issues

by ikegami (Pope)
on Feb 01, 2006 at 18:26 UTC ( #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 10: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
Node Status?
node history
Node Type: note [id://527192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2020-11-28 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?