I need to remove all unique entries from a list of lists such that all lists are the same. I have done this but I'm sure there must be a better way?

Data structure for array paring example
use strict; use warnings; use Data::Dumper; my $temp = [ [ '/', '/index.html', '/products/' ], [ '/', '/index.html', ], [ '/', '/index.html', '/products/' ], [ '/', '/index.html', '/test.html', ] ]; # Count for the smallest array my $size = @{$temp->[0]}; my $numterms = @{$temp}; # Build the initial list my $seen = {}; map{ $seen->{$_}++} @{$temp->[0]}; my $success = 1; for(my $i = 1; $i < @{$temp}; $i++) { map { $seen->{$_}++ if exists($seen->{$_});}(@{$temp->[$i]}); } my @results; while(my ($key,$value) = each(%{$seen})) { if($value == $numterms) { push @results,$key; } } print STDERR Data::Dumper->Dump([\@results]);
Note that the datastructure is typically two to three times the size of the one above. The code prints (when run):

C:\WINNT\PROFILES\PROCTOS\DESKTOP>perl test.pl $VAR1 = [ '/', '/index.html' ]; C:\WINNT\PROFILES\PROCTOS\DESKTOP>


I have seen code for returning all unique elements for lists but not to do this.

Thanks
Simon

In reply to Remove unique elements from a list of lists by simon.proctor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.