in reply to Telephone - Nested Loops

Note: I have never used NestedLoops before reading this question, so take this with a grain of salt.

Having said that, and having read through the docs a bit, NestedLoops lets you do with a single loop what you'd otherwise use a chain of N foreach loops to do, i.e. collectively walk across an N-dimensional parameter space.

In your phone number example, N=7, and each dimension would be a digit in the whole number. To keep it simple I'm going to use a 3 digit number (N=3) instead.

So, instead of writing:

@A_options = @B_options = @C_options = qw(0 1 2 3 4 5 6 7 8 9); foreach my $A (@A_options) { foreach my $B (@B_options) { foreach my $C (@C_options) { print $A . $B . $C . ;\n"; } } }
you could write:
@A_options = @B_options = @C_options = qw(0 1 2 3 4 5 6 7 8 9); NestedLoops( [\@A_options,\@B_options,\@C_options], sub {print $_[0] . $_[1] . $_[2] . "\n";} );
The information about where you are in the N-dimensional loop is passed to the called subroutine as consecutive params under @_.

Good luck,
- Dynamo