SPUG: itm 60 in effective perl programming
John W. Krahn
krahnj at telus.net
Thu Feb 24 04:34:16 PST 2005
Yitzchak Scott-Thoennes wrote:
> On Thu, Feb 24, 2005 at 12:37:45AM -0800, Ben Reser wrote:
>
>>Perhaps they meant this:
>>perl -pe 's/\n/ /' file
>>
>>tr would probably be moderately better:
>>perl -pe 'tr/\n/ /'
>>
>>But I'd prefer the following:
>>perl -pe 'chomp; $_ .= " "' file
>
>
> 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'/.*/;$\.=$&.$"}{'
John
--
use Perl;
program
fulfillment
More information about the spug-list
mailing list