in reply to Eliminate Array of array duplication

Hi,

@AoD = (11,12,22 ,11,12,22 ,13,15,18); foreach my $v1(@AoD) { print $v1."\n"; } print "======\n"; my %hash = map { $_, 1 } @AoD; my @AoD = keys %hash; print "======\n"; foreach my $v(@AoD) { print $v."\n"; }

By the above code We can remove duplicate in array

Replies are listed 'Best First'.
Re^2: Eliminate Array of array duplication
by ikegami (Patriarch) on May 19, 2011 at 10:15 UTC

    His bad formatting mislead you. He wants to turn

    @AoD = ([11,12,22], [11,12,22], [13,15,18]);

    into

    @AoD = ([11,12,22], [13,15,18]);

    Ignoring that, the advantage of previously mentioned

    my %seen @AoD = grep !$seen{$_}++, @AoD;

    over your solution

    my %seen = map { $_ => 1 } @AoD; @AoD = keys(%seen);

    is that the former maintains the order of the elements it keeps.