Tony Bowden <[EMAIL PROTECTED]> writes:

> On Wed, Jan 03, 2001 at 11:16:06AM +0000, Piers Cawley wrote:
> > > How can I do this:
> > >   my @list = qw/foo bar foo baz/;
> > >   my %hash = map { $_ => 1 } @men;
> > >   my @sort = sort keys %hash;
> > >   print "We have @sort\n"; # foo bar baz
> > > without the %hash?
> 
> > my $last;
> > do {print $_ unless $_ eq $last; $last = $_} for sort @list
> > Dunno if it's quicker than the cunning tricks with map, but hey, it
> > works. 
> 
> Ah, but my question was badly phrased. I needed to end up with @sort, not
> a printed list ... 

Ah:

do {push(@sorted, $_) unless $_ eq $last; $last = $_} for sort @list;

Can't be bothered to benchmark it...

-- 
Piers

Reply via email to