Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Massive expansion of a hash of arrays?

by Anonymous Monk
on Jul 18, 2014 at 00:04 UTC ( [id://1094145]=note: print w/replies, xml ) Need Help??


in reply to Re: Massive expansion of a hash of arrays?
in thread Massive expansion of a hash of arrays?

Yes i think im over estimating my data set. Its more like 15 keys but each key will have 2-3 values. Only one of them has 12 values.

how would CrossProduct deal with arrays that you didnt want to expand? One of the end values might be an array. I would want to copy that as is<\p>

  • Comment on Re^2: Massive expansion of a hash of arrays?

Replies are listed 'Best First'.
Re^3: Massive expansion of a hash of arrays?
by Cristoforo (Curate) on Jul 19, 2014 at 02:02 UTC
    Something like this would prevent one of the arrays from being processed in the cross product.
    #!/usr/bin/perl use strict; use warnings; use Set::CrossProduct; my %hash=('ID' => { 'key1' => ['key1_val1', 'key1_val2'], 'key2' => ['key2_val1', 'key2_val2'], 'key3' => ['one', 'two'] } ); for my $id (keys %hash) { my $key3 = delete $hash{$id}{key3}; 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"; } print "@$key3\n"; }
    Prints
    ID 1 key2_val1 key1_val1 ID 2 key2_val1 key1_val2 ID 3 key2_val2 key1_val1 ID 4 key2_val2 key1_val2 one two

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-18 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found