in reply to dynamic map "quadrant" indexing

Ok - I did it. Wasn't that hard after all, and now I'll make the code more elegant.
use strict; my $lvl ="@ARGV"; my $out = &idx($lvl); print "@$out\n"; sub idx { my $lvl = shift; my @out = qw(a1 b1 c1 d1); if($lvl == 1) { return \@out; } else { my @tmp = (); for my $o (@out) { push @tmp, "$o$_" for(@{&idx($lvl-1)}); } @out = @tmp; } return \@out; }
Marcel

Replies are listed 'Best First'.
Re^2: dynamic map "quadrant" indexing
by Anonymous Monk on Aug 14, 2005 at 13:42 UTC
    Uhm... well forget it, the code is crap. This one does the right thing:
    sub idx { my $lvl = shift; # ARG1: get level my @out = qw(a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4); # init OUT array return \@out if($lvl == 1); # bail out if lvl = 1 my @tmp; for my $o (@out) { push @tmp, map { "$o$_" } @{&idx($lvl-1)}; } return \@tmp; }
    Probably I should not do my coding sunday morning. Marcel