Nick Leverton wrote:
On Tue, Jun 07, 2005 at 07:33:27PM -0400, Bob wrote:
...like to fix...allowing duplicate recipients

sub _uniq {
my %u = () ; for ( @_ ) { $_ and $u{$_} = 1 } ; keys %u if ref \%u ;
}

There's an even neater way to write uniq, which also preserves the order:

my %u = (); grep { ! ($u{$_}++) } @_;

List operators are so useful !  A better perl bod than me could probably
avoid the named hash too :)

Nick
Bob says:

#!/usr/bin/perl -w
use strict; # strict and warn fail a lot of anon hash tricks, so...
sub uniq {
 grep { $_ ne $/ and $/ = $_ } sort grep { $_ } @_ ;
} # no named hash

Reply via email to