in reply to Passing List::Compare a list of arrays

        $lcm=List::Compare=>new(\

List::Compare->new() (note arrow operator, not fat comma) expects a list of ARRAY refs as its arguments. I don't know enough about your algorithm to write the exact code for you, but it looks like, for example, $HoAncestors{$taxid} is just such an ARRAY ref, so just send it straight to List::Compare->new($HoAncestors{$taxid}, ...), filling in the ... with as many other ARRAY refs as you want to include in the same comparison (i.e., the ones you wish to calculate the intersection of).

use 5.012; use warnings; use List::Compare; my %hash = ( a => [ qw/foo bar baz for/ ], b => [ qw/bar bells are for tough guys/ ], c => [ qw/belly up to the bar for beer/ ], d => [ qw/d is not used for comparison/ ], ); my $lc = List::Compare->new($hash{a}, $hash{b}, $hash{c}); # my $lc = List::Compare->new(@hash{ qw/a b c/ }); # Or with hash slic +e my @intersection = $lc->get_intersection; say "@intersection";

Output:

bar for

Replies are listed 'Best First'.
Re^2: Passing List::Compare a list of arrays
by AWallBuilder (Beadle) on Jul 12, 2013 at 10:57 UTC

    thankyou. My problem is that I am incorporating this in a loop so that I do not know how many Hashes of arrays (ie. how many taxids) I will have each time

    here I have tried to illustrate a bit better what I want (although I know its not correct). Or is there some way of pushing or pasting the arrays into a list that I then pass to List::Compare

    my %HoAncestors;my @intersection; foreach my $qu (keys %HoTxHits) { my $array_list;my $numb_taxids; # go through each taxid, get ancestors, then find the intersec +tion foreach my $taxid (@{$HoTxHits{$qu}}){ $numb_taxids=scalar(@{$HoTxHits{$qu}}); my $queryTaxid=$taxid; while ((exists $HoPar{$queryTaxid}) && ($HoPar{$queryT +axid} != 1)) { my $parent=$HoPar{$queryTaxid}; push (@{$HoAncestors{$taxid}},$parent); $queryTaxid=$parent; } } my $lcm=List::Compare->new($HoAncestors{$taxid}[0]..$HoAncesto +rs{$taxid}[$numb_taxids-1]); @intersection=$lcm->get_intersection; }