in reply to Re: Comparing multiple arrays in Hash of Arrays using List::Compare
in thread Comparing multiple arrays in Hash of Arrays using List::Compare

That works but I don't understand why. Can you explain?

I would think that just passes the key names to the constructor. But obviously that's wrong.

Edit: I see, you used values and not key names.
  • Comment on Re^2: Comparing multiple arrays in Hash of Arrays using List::Compare

Replies are listed 'Best First'.
Re^3: Comparing multiple arrays in Hash of Arrays using List::Compare
by BrowserUk (Patriarch) on Feb 13, 2006 at 23:08 UTC

    Because the contructor is expecting a list of array references, and that is exactly what the values of your hash are.

    The downside of using values here is that you do not know what order the array references are passed to the constructor which could make interpreting the results difficult. If this is a problem, then you can define that order by using a hash slice like this:

    my $lc = List::Compare->new( @hash{ sort keys %hash } );

    which will pass the array references to the constructor in whatever order you sort the keys. As shown above, this would be alphanumeric ascending, but as your keys are numeric (why aren't you using an array instead of a hash?), you might prefer

    my $lc = List::Compare->new( @hash{ sort{ $a <=> $b} keys %hash } );

    depending upon how you intend to use the results.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.