SPUG: itm 60 in effective perl programming

John W. Krahn krahnj at telus.net
Thu Feb 24 04:49:34 PST 2005


John W. Krahn wrote:
> Yitzchak Scott-Thoennes wrote:
>>
>> For completeness:
>>
>> perl -pe'substr($_,-1,1," ")' file
>>
>> or
>>
>> perl -pe'substr($_,-1)=" "' file
>>
>> or
>> perl -pe'/\n/;$_="$` "' file
>>
>> or
>>
>> perl -pe'/.*/;$_="$& "' file
>>
>> or even
>>
>> perl -pl40w010e0 file
> 
> Octal 010 is the backspace character, it should be 012 for newline:
> 
> perl -012l40pe0
> 
> 
> perl -lpe'$,.=$_.$"}{$\=$,'
> 
> or
> 
> perl -pe'/.*/;$\.=$&.$"}{'

Or to do what the original did without using a regular expression:

perl -lpe'$;.=$_.(--$|?$":$/)}{$\=$;'

or even

perl -pe'/.*/;$\.=$&.(--$|?$":$/)}{'



John
-- 
use Perl;
program
fulfillment


More information about the spug-list mailing list