Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Creating combinations using arrays

by DreamT (Pilgrim)
on Mar 05, 2013 at 16:33 UTC ( #1021865=note: print w/replies, xml ) Need Help??


in reply to Re: Creating combinations using arrays
in thread Creating combinations using arrays

Well, the problem is that i don't know which properties that are available at the time, so instead of @colors, @sizes, @shapes, I need something more dynamic.
  • Comment on Re^2: Creating combinations using arrays

Replies are listed 'Best First'.
Re^3: Creating combinations using arrays
by LanX (Bishop) on Mar 05, 2013 at 23:07 UTC
    > Well, the problem is that i don't know which properties that are available at the time, so instead of @colors, @sizes, @shapes, I need something more dynamic.

    So use a recursive function!

    rec_for([1..3],["a".."c"],[10..13]); my @tuple; sub rec_for { if (@_) { my $a_list = shift; for my $x (@$a_list) { push @tuple, $x; rec_for(@_); pop @tuple; } } else { print "tuple: @tuple\n"; } }

    /usr/bin/perl -w /home/lanx/B/PL/PM/recursive_for.pl tuple: 1 a 10 tuple: 1 a 11 tuple: 1 a 12 tuple: 1 a 13 tuple: 1 b 10 tuple: 1 b 11 ...

    Cheers Rolf

    UPDATE

    if you need the result in a %hash, just alter the routine to process key-value pairs

    rec_for(a=>[1..3],b=>["a".."c"],c=>[10..13]);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1021865]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2018-08-20 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (196 votes). Check out past polls.

    Notices?