Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Multiple Permutation handling

by midget2000x (Novice)
on Mar 02, 2013 at 07:19 UTC ( #1021395=note: print w/ replies, xml ) Need Help??


in reply to Multiple Permutation handling

Thanks for the help guys, I really appreciate it. Anyone want a take on a curveball? What if some SKUs just have one set of options (like size only), but the next SKU has 3 sets (size, color, type), and the next one has 2 (size and color)? Can the code be make to "permutate" only over the available sets for each SKU?


Comment on Re: Multiple Permutation handling
Re^2: Multiple Permutation handling
by ggoebel (Sexton) on Mar 02, 2013 at 11:52 UTC
    use strict; use warnings; use integer; # See http://www.perlmonks.org/?node_id=154008 my @permutation = ( [['SKU'],[1..3],[qw(T S L H)],[qw(S M L XL 2X)],[qw(BLU GRN WHT BL +K)]], [['SKU'],[4..5],[qw(S M L XL 2X)]], [['SKU'],[6],[qw(S M L XL 2X)],[qw(BLU GRN WHT BLK)]] ); for my $p (@permutation) { my $iter = make_permutator(@$p); while (my @els = $iter->()){ print @els, "\n"; } } sub make_permutator { my @idx_link = (0, @_); my $idx; return sub { $idx = $idx_link[0]++; my @ret; for my $i (1..$#idx_link) { push @ret, $idx_link[$i][$idx % @{$idx_link[$i]}]; $idx /= @{$idx_link[$i]}; } return $idx ? () : @ret; } } 1; __END__

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2015-07-05 07:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls