So that you have an array of normalized arrays, and then sort the large one and filter out duplicates like so:my @array = ( [ sort @value1 ], [ sort @value2 ], # ... and so forth );
This will only return array unique arrays. Then you simply assign to your hash:my $prev = []; @array = grep { my $i = 0; my $ret = 0; $ret = 1 if $#$prev != $#$_; while ($ret && $i <= $#$prev and $i <= $#$_){ $ret = 1 if $prev->[$i] ne $_->[$i]; } $ret; } sort { my $i = 0; my $ret = 0; loop: while (1) { if ($i <= $#{$a} and $i <= $#{$b}){ # test if we still have so +mething to compute $ret = $a->[$i] cmp $b->[$i]; # compute the difference of +this element last loop if $ret; # if there's a difference return $i++; } else { # if the arrays are equal to this point in terms of e +lements, but not in length, we decide on the longer one $ret = $#{$a} <=> $#{$b}; # determine by length last loop; } } $ret; } @array;
$myhash{$key1} = $array[0]; $myhash{$key2} = $array[1];
In reply to Re: How to compare hash value
by nothingmuch
in thread How to compare hash value
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |