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

Re: [FWP] Recursion, anyone?



>From fwp-l Wed Apr 11 14:21:08 2001

On Wed 11 Apr, yanick1@sympatico.ca wrote:
> On Wed, Apr 11, 2001 at 03:08:58PM -0400, Kort, Eric wrote:
> > Anyone care to improve on my first attempt?  If someone reduces this to a
> > one-liner, I promise never to post again!
>
> I only managed a two-liners. Drat. ;)
>
> #!/usr/bin/perl
> @e=(A..Z,a..z,0..9,'-');@i=(0)x shift;$\="\n";while($f=1){print@e[@i];
> map{$f&&((++$i[$_]>@e?$i[$_]:$f)=0)}0..@i-1;$f&&exit;}
>

An even better solution...

perl -le'sub x{if(@_<$ARGV[0]){x(@_,$_)for(a..z,0..9,"-")}print@_}x'

68 chars...  (It does print one blank line at the end however)

Richard

-- 

Richard@waveney.org

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