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

Re: [FWP] The Perl Golf Apocalypse Experience



On Wed, Aug 02, 2000 at 09:20:20AM -0500, Tim Ayers wrote:
> 
>  + Implement cat(1):
> 
>     perl -pe\; <file>+

      perl -pe: <file>+

>  + Implement yes(1):
> 
>     perl -le'print"@ARGV"||"y"while 1'

Equally well:

      perl -le'{print"@ARGV"||"y";redo}'

> 
>  + Strip off leading whitespace from each line of a file
> 
>     perl -i -pes/^\\s+// <file>
>  
>  + Copy a file
> 
>    perl -e'open B,">".pop;print B<>' <source-file> <target-file>

     perl -e'`cp @ARGV`' <source-file> <target-file>

>  + "Backup" files in a directory tree to *.bak
> 
>     perl -e'sub x{($a)=@_;(-f)?(open(A,$_),open(B,">$_.bak"),print B<A>):x($_)for<$a/*>}x(shift)' <directory>

      perl -e'chdir pop;`perl -i.bak -pe: * .*`' <directory>

Or if this is allowed:

      cd <directory>;perl -i.bak -pe: * .*



Abigail

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe