in reply to Minimize Hash Key Value Combinations

I do not understand how you derived the result from the data, but why are you not enumerating your strings and use the data as displayed above? (Or is this what you mean by calling the values by reference?)

  • Comment on Re: Minimize Hash Key Value Combinations

Replies are listed 'Best First'.
Re^2: Minimize Hash Key Value Combinations
by AlexTape (Monk) on Nov 18, 2013 at 13:46 UTC
    if you take a closer look to data and result you will see that the relations are the same..
    e.g.
    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';
      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'

      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]
      "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';