[EMAIL PROTECTED] wrote:
> I have 300+ text files w/ Mac line endings ... does anyone 
> know of a module to facilitate cleaning this up?

Don't need a module.

> Alternatively, does anyone know the escaped character sequence
> for Mac line endings

carriage return ("\015", or also "\r" on non-Macs).

> so I could just s///g the file?

Or you could just use command-line switches:

    perl -i.bak -lp015e1 *.txt

(add -MG to do automatic globbing if your shell doesn't do so automatically,
e.g. with command.com or cmd.exe on Win32.)

Explanation:

* -i.bak enables "in-place editing" mode, saving the original file as
<original name>.bak. It also means that output will go to the new version of
the file, under the original filename

* -l sets $\ (the output record separator) to $/ (the input record
separator). The $/ hasn't been set and so has the default value "\n". This
causes all records printed to have a "\n" tacked on (which will be turned
into "\r\n" on Win32 unless you use binmode). It also causes records read in
by -p to be automatically chomped.

* -p causes all records read in to be printed out automatically

* -015 is the -0 switch with an argument of 15: it sets $/ (the input record
separator) to "\015" or "\cM". This it the value that will be chomped()
later on.

* -e1 is the -e switch with an argument of 1. For each input line of the
file, the Perl code "1;" will be evaluated. A quick no-op. (And
warnings-free, by special dispensation.)

* *.txt is the filespec, representing the files you want to have changed.
They'll be read one after the other since -p loops over @ARGV.

Hope this helps!

Cheers,
Philip
-- 
Philip Newton <[EMAIL PROTECTED]>
All opinions are my own, not my employer's.
If you're not part of the solution, you're part of the precipitate.
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to