Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all I would like to note that nohat's answer simply does not work. Try running it, and look at the output in Data::Dumper to verify that.</p> <p>That said, your question is not well-posed. It looks like you are using sets as arrays. How do you wish to handle duplicates? How do you want to handle complex data structures? What order do you want elements in? For ease I'll assume that the answers are squash duplicates, it is OK to stringify complex data structures, and order does not matter. In that case the following is a perfectly adequate answer:</p> <pre><code>sub list_compare { my @lists = @_; my @answers; for my $list (@lists) { my %in_list = map {$_=&gt;1} @$list; # We have this list. my @more_answers = [keys %in_list]; for my $answer (@answers) { push @more_answers, [grep $in_list{$_}, @$answer]; } push @answers, @more_answers; } return @answers; } </code></pre> <p>If you want to adjust those assumptions, you'll need to adjust the code. For example not squashing complex data structures and not squashing duplicates can be done with:</p> <pre><code>sub list_compare { my @lists = @_; my @answers; for my $list (@lists) { my %in_list = map {$_=&gt;1} @$list; # We have this list. my @more_answers = [@$list]; for my $answer (@answers) { push @more_answers, [grep $in_list{$_}, @$answer]; } push @answers, @more_answers; } return @answers; } </code></pre> <p>This is, however, using the stringification of the data structure to check whether things that exist in one exist in another. Relaxing that condition would require somewhat more work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload