If you like simple, try this:

#! perl -slw use strict; sub nFor(&@) { my $code = shift; die "First argument must be a code ref" unless ref( $code ) eq 'CO +DE'; my @limits = @_; my @indices = ( 0 ) x @limits; for( my $i = $#limits; $i >= 0; ) { $i = $#limits; $code->( @indices ), ++$indices[ $i ] while $indices[ $i ] < $limits[ $i ]; $i = $#limits; $indices[ $i ] = 0, ++$indices[ --$i ] while $i >= 0 and $indices[ $i ] == $limits[ $i ]; } } my @list1 = ( 1, 2 ); my @list2 = qw[ a b ]; my @list3 = qw[ # * & ]; ## Your code goes in the block below ## The list is the number of elements in each array ## Each time the block is called ## $_[0] is the index to use in the first list ## $_[1] " ## $_[2] 8 ## etc. nFor { print join '', $list1[ $_[0] ], $list2[ $_[1] ], $list3[ $_[2] ]; } 2,2,3; __END__ C:\test>795953.pl Possible attempt to put comments in qw() list at C:\test\795953.pl lin +e 23. 1a# 1a* 1a& 1b# 1b* 1b& 2a# 2a* 2a& 2b# 2b* 2b&

If your lists are arranged as a list of lists, things get a little tidier.

Update:To clarify, if your lists are arranged as an AoAs, then the problem generalises to:

my @lists = ( [ 1, 2 ], [ qw[ a b ] ], [ qw[ # * & ] ] ); nFor { print join '', map $lists[ $_ ][ $_[ $_ ] ], 0 .. $#_; } map scalar @$_, @lists;

Which handles any number of lists or items transparently.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)

In reply to Re: permutations problem by BrowserUk
in thread permutations problem by perlrocks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.