Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Remove unique elements from a list of lists

by PrakashK (Pilgrim)
on Feb 27, 2002 at 14:44 UTC ( #147908=note: print w/replies, xml ) Need Help??


in reply to Remove unique elements from a list of lists

I need to remove all unique entries from a list of lists such that all lists are the same.
From what you have done, it seems to me like you want to get the elements which exist in all lists.

I can't suggest a better way, but it can be shorter be removing unnecessary code.

use strict; use warnings; use Data::Dumper; my $temp = ... # your list of lists here my $numterms = @$temp; my $seen = {}; for my $term (@$temp) { map { $seen->{$_}++ } @$term; } my @results = grep {$seen->{$_} == $numterms} keys %$seen; print STDERR Data::Dumper->Dump([\@results]);
/prakash

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://147908]
help
Chatterbox?
Discipulus some monks here around are flammable.. or well they interact like a porcupine and an airbaloon

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-01-20 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (173 votes). Check out past polls.