bradcathey has asked for the wisdom of the Perl Monks concerning the following question:
but the AoH structure has me a bit confused how this apply. Anyway, here's my code-that-works-but-looks-too-long. Thanks!my @keys = grep { $hash{$_} eq $value } keys %hash;
#!/usr/bin/perl use Data::Dumper; use strict; my @AoH = ( { page => 'spring' }, { page => 'winter' }, { page => 'fall' }, { page => 'summer' }, { page => 'spring' } ); my @allvalues; for my $i ( 0 .. $#AoH ) { push ( @allvalues, $AoH[$i]{ page } ); } my %seen; my @duplicates = grep { $seen{$_} ++ } @allvalues; for ( @duplicates ) { for my $i ( 0 .. $#AoH ) { if ( $AoH[$i]{ page } eq $_ ){ delete $AoH[$i]{ page }; splice @AoH,$i,1; last; } } } print Dumper (@AoH);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there better way to delete dups in an AoH?
by Happy-the-monk (Canon) on Jun 06, 2004 at 13:50 UTC | |
by bradcathey (Prior) on Jun 06, 2004 at 20:55 UTC | |
by Happy-the-monk (Canon) on Jun 06, 2004 at 21:20 UTC | |
by bradcathey (Prior) on Jun 06, 2004 at 23:14 UTC | |
by Roy Johnson (Monsignor) on Jun 06, 2004 at 23:30 UTC | |
| |
by qq (Hermit) on Jun 07, 2004 at 00:01 UTC | |
| |
|
Re: Is there better way to delete dups in an AoH?
by hv (Prior) on Jun 06, 2004 at 14:31 UTC |