in reply to More efficient way to get uniq list elements from list of lists
Use a hash:
use Data::Dumper; use strict; use warnings; sub edges2vertices { my %vertices; for my $i ( 0 .. $#_ ) { $vertices{$_[$i][$_]} = 1 for (0 .. $#{$_[$i]}); } return sort keys %vertices; } my @E = ([1,2], [1,3], [2,3,7,8], [2,4], [3,4]); my @nv= edges2vertices(@E); print Dumper(\@nv);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: More efficient way to get uniq list elements from list of lists
by simonm (Vicar) on Nov 11, 2004 at 08:20 UTC | |
by Aighearach (Initiate) on Nov 11, 2004 at 12:25 UTC | |
by simonm (Vicar) on Nov 11, 2004 at 18:52 UTC | |
by Aighearach (Initiate) on Nov 11, 2004 at 23:01 UTC |