monkfan has asked for the wisdom of the Perl Monks concerning the following question:
So that withsub edges2vertices { #AoA to uniq array elem; my @edges = @_; my @vertices; my @uniqv; for my $i ( 0 .. $#edges ) { for my $j ( 0 .. $#{$edges[$i]} ) { push @vertices, $edges[$i][$j]; } } @uniqv = sort keys %{{map {$_,1} @vertices}}; return @uniqv; }
my @E = ([1,2], [1,3], [2,3], [2,4], [3,4]); my @nv; @nv = edges2vertices(@E); # will return: __END__ $VAR1 = [ '1', '2', '3', '4' ];
|
|---|