Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; my $array_ref_x = [ [ 'ALICE WONDER', '9876543', '2009', '11.00', '711', '0', '0', '8' ], [ 'ALICE WONDER', '9876543', '2009', '11.00', '711', '3', '2', '0' ], ]; my %dual_ck = (); my $all_val; my @unique = (); foreach my $rows (@$array_ref_x){ next if $dual_ck{ $rows }++; push @unique, $rows; # trying here but did not work #my @unique = grep { ! $dual_ck{ $_ }++ } $rows; @$all_val = @unique; } print Dumper(@$all_val); #=cut # Here is what a happy end should be like ;-) =comment my $final_vals = [ [ 'ALICE WONDER', '9876543', '2009', '11.00', '711', '3', '2', '8' ], ]; =cut
20090503 Janitored by Corion: Removed stray bold tag, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Keeping Unique Elements in Array!
by almut (Canon) on May 01, 2009 at 17:55 UTC | |
by Anonymous Monk on May 01, 2009 at 18:38 UTC | |
by almut (Canon) on May 01, 2009 at 18:46 UTC | |
by Anonymous Monk on May 01, 2009 at 18:55 UTC | |
by almut (Canon) on May 01, 2009 at 19:03 UTC | |
by Anonymous Monk on May 01, 2009 at 19:00 UTC | |
by Anonymous Monk on May 01, 2009 at 19:17 UTC | |
by almut (Canon) on May 01, 2009 at 19:48 UTC | |
|