simon.proctor has asked for the wisdom of the Perl Monks concerning the following question:
Note that the datastructure is typically two to three times the size of the one above. The code prints (when run):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]);
C:\WINNT\PROFILES\PROCTOS\DESKTOP>perl test.pl $VAR1 = [ '/', '/index.html' ]; C:\WINNT\PROFILES\PROCTOS\DESKTOP>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Remove unique elements from a list of lists
by PrakashK (Pilgrim) on Feb 27, 2002 at 14:44 UTC | |
|
(jeffa) Re: Remove unique elements from a list of lists
by jeffa (Bishop) on Feb 27, 2002 at 15:03 UTC | |
|
Re: Remove unique elements from a list of lists
by particle (Vicar) on Feb 27, 2002 at 15:02 UTC | |
|
Re: Remove unique elements from a list of lists
by simon.proctor (Vicar) on Feb 27, 2002 at 15:27 UTC | |
by vagnerr (Prior) on Feb 27, 2002 at 16:20 UTC | |
|
Re: Remove unique elements from a list of lists
by Zaxo (Archbishop) on Feb 27, 2002 at 15:26 UTC |