in reply to Massive expansion of a hash of arrays?
This prints#!/usr/bin/perl use strict; use warnings; use Set::CrossProduct; my %hash=('ID' => { 'key1' => ['key1_val1', 'key1_val2'], 'key2' => ['key2_val1', 'key2_val2'] } ); for my $id (keys %hash) { my @data = values %{ $hash{$id} }; my $cp = Set::CrossProduct->new( \@data ); my $i = 1; while( my $array_ref = $cp->get ) { print join( " ", $id, $i++, @$array_ref ), "\n"; } }
Note that my @data = values %{ $hash{$id} }; does not give values corresponding to 'key1', 'key2' ... 'key15' order. Some change in how the order of values appear would need to be made to get that.ID 1 key2_val1 key1_val1 ID 2 key2_val1 key1_val2 ID 3 key2_val2 key1_val1 ID 4 key2_val2 key1_val2
Hope this helps,
Chris
Update: You will get huge amount of combinations for 12 rows with 15 items in each array. 15 ^ 12 = 129,746,337,890,625
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Massive expansion of a hash of arrays?
by Anonymous Monk on Jul 18, 2014 at 00:04 UTC | |
by Cristoforo (Curate) on Jul 19, 2014 at 02:02 UTC |