[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] keeping my newlines straight



On Thu, Mar 09, 2000 at 07:52:49AM -0800, Brian McNett wrote:
> Bart Lateur <bart.lateur@skynet.be> wrote:
> 
> >	#perl -i.bak
> >	undef $/; #whole file at once
> >	while(<>) {
> >		s/\012|\015\012|\015/\n/g;
> >		print;
> >	}
> 
> Better...
> 
> #!perl -l000i.bak
> s/\012|\015\012|\015/\n/g;
> print;

That code doesn't do anything useful.


> ...which is using the switches to their utmost extent (at least that 
> extent on the Mac).
> 
> -l000 is just another way of saying "undef $/;"

That is not correct.  The -l switch sets $\ (the output record separator),
and has no effect on $/ (the input record separator).  Also note that
"\000" is not the same as undef.


> can't do -p in this instance, because we're processing line endings 
> specifically, and -p in the context of -l does chomp() on the input. 
> Otherwise I'd be able to drop the explicit print().

Without -p or -n to provide the while (<>) loop, your code never reads its
input.  Never reading its input means it has nothing useful to output.
Your code prints the null character and then exits.

You shouldn't be using -l anyway.  In addition to chomp()ing the input, it
also appends $/ to the output, neither of which you need to do for this
code.


#!perl -p0377i.bak
s/\012|\015\012?/\n/g;


Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org