Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: Minimize Hash Key Value Combinations

by AlexTape (Monk)
on Nov 18, 2013 at 13:46 UTC ( #1063088=note: print w/replies, xml ) Need Help??

in reply to Re: Minimize Hash Key Value Combinations
in thread Minimize Hash Key Value Combinations

if you take a closer look to data and result you will see that the relations are the same..
A->[1, 2, 3, 4, 5, 6, 7]
is still given. enumerating CAN be the first step of the approach to get an easier comparison..
[1] => StringA [2] => StringB ... [A] => [1, 2] [B] => [2]
But as i want to print that to an file, StringB will be there twice. e.g. StringB is equal to a data volume of 3gb. the file will be 6gb. for that i want to print this:
[A] => [1] [A, B] => [2]
$perlig =~ s/pec/cep/g if 'errors expected';

Replies are listed 'Best First'.
Re^3: Minimize Hash Key Value Combinations
by Arunbear (Prior) on Nov 18, 2013 at 14:39 UTC
    Where do StringA, StringB etc. come from? If they are in files, couldn't you store the file paths rather than their values?
    [1] => '/path/to/StringA/data' [2] => '/path/to/StringB/data'
Re^3: Minimize Hash Key Value Combinations
by hdb (Monsignor) on Nov 18, 2013 at 14:40 UTC

    Here is my attempt:

    use strict; use warnings; use Data::Dumper; my @data = map { [ [split /,\s*/, $_->[0]], [split /,\s*/, $_->[1]] ] } map { /\[(.*)\]\s*=>\s*\[(.*)\]/ ? [ $1, $2 ] : () } <DATA>; my %inverted; for my $d (@data) { undef @{$inverted{$_}}{@{$d->[0]}} for @{$d->[1]}; } my %invertagain; push @{ $invertagain{join ",", sort keys %{$inverted{$_}}} }, $_ for k +eys %inverted; print Dumper \%invertagain; __DATA__ [a, b, c] => [1, 2, 3] [b, c] => [2, 3, 4, 5] [a, c, d] => [4, 5, 6, 7] [d] => [1, 2, 6]
Re^3: Minimize Hash Key Value Combinations
by LanX (Sage) on Nov 18, 2013 at 13:58 UTC
    "if you take a closer look" to what you said:

    > the result should look like this:

    [a, b, c, d] => [1, 2] [b, c] => [2]

    which doesn't make sense, don't you agree?

    You are talking about a "hashtree" but the data shown has nothing to do with HoH.

    The data shown isn't even valid Perl, keys are strings never arrays.

    have a look at How (Not) To Ask A Question

    Asking a good question is often the best answer! :)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    ) OP updated now...

      first you are right.. i made the result manually.. that was a simple mistake.. :)

      actually it is an hash tree.. but i dont want to deflect the problem with code snippets..
      keys are strings never arrays
      i dont agree.. just take a look at Hash::Multikey or perldsc or maybe it is a nested structure like this:
      #!/usr/bin/perl -w use strict; use warnings; my %hash; $hash{'number'}{'even'} = [24, 44, 38, 36]; $hash{'number'}{'odd'} = [23, 43, 37, 35]; foreach my $i(keys %hash){ print $i; foreach my $j(keys %{$hash{$i}}){ print "\t".$j."\t"; print join(" ",@{$hash{'number'}{$j}})."\n"; } }
      furthermore thats offtopic :)
      $perlig =~ s/pec/cep/g if 'errors expected';

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-09-29 15:05 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (125 votes). Check out past polls.