useful snippet for win32 users, converts line breaks from *nix to win32 via the @ARGV array, so it works via command line and drap & drop. if you know how, you can even put it in the right-click file context menu. you could also switch the chars for $r and $n and use it on *nix systems.
if(!@ARGV) { print <<"EOC"; Usage: reformat.exe -b files [-b] : include this flag if you would like to automatically backup all files being reformatted [files] : files to reformat EOC sleep; } @f = @ARGV; if($ARGV[0] eq '-b') { $b = 1; shift(@ARGV); } else { $b = 0; } foreach $f (@f) { $f =~ s/\\/\//g; open(FILE,"$f"); @file = <FILE>; close(FILE); if($b) { open(BKUP,">$f.bak"); foreach $i (@file) {print BKUP $i} close(BKUP); } foreach (@file) {chomp} $file = join("\n",@file); $r = chr(13); $n = chr(10); $file =~ s/$r/$n/g; open(FILE,">$f"); print FILE $file; close(FILE); }

Replies are listed 'Best First'.
Re (tilly) 1: Text reformat
by tilly (Archbishop) on Sep 03, 2001 at 18:10 UTC
    You can make this shorter with the command-line switches in perlrun. In fact if you toss in a little knowledge about how line ending issues work, the following when run on a Windows machine will turn Unix, DOS, or Mac line endings into DOS endings:
    perl -pi.bak -e 1 file1 file2 file3
    On Unix you can convert to local text format with:
    perl -pi.bak -e 's/\r\n?|\n\r?/\n/g' file1 file2 file3
    That should work on MacOS as well, but I don't have it here to test. (I would be able to get it to work on all 3 platforms, but DOS likes to use " to group arguments in the command line, while Unix likes to use ' for the same purpose. I couldn't figure out how to get around that incompatibility in one line.)