http://www.perlmonks.org?node_id=622785


in reply to Telephone - Nested Loops

NestedLoops takes a structure over which it will iterate but it needs a second parameter to tell it what to do per iteration. So you could do your thing by passing it a 7- deep nested array by reference and a code ref like sub { print "$_\n" for @_; }; But as a rule, such predictable structures should never even be built (update: I have a habit of not building ranges like 0..7 even though that's small, because I don;t want to build in memory a 0..colussus by accident!). So the thing should never even get the chance to be passed to a method; rather the algorithm should be a bit smarter.

# updated to add leading zeroes sub Arbitel { # takes number of digits as argument my $count = shift; my $limit = 10**$count; for ( my $i = 0; $i < $limit; $i++ ) { print Lzro( $count, $i ) . "\n"; } } sub Lzro my ( $count, $number ) = @_; substr( ( '0' x $count ) . $number, -$count ); }
More update: my decision chart:

"Can it be mapped to a simple virtual structure? Y: don't build it and don;t bother to use a CPAN module to generate or iterate it.

N: "Can the structure be iterated virtually without building it? N: use Algorithm::

Y: "Is there a method for it in Math::Combinatorics? Y: use that then N: use Algorithm::

__________________________________________________________________________________

^M Free your mind!