On 4 Jan 2001, Piers Cawley wrote:

> 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...

This would be very slow for the dutch national flag, as it sorts the large
list rather than the small one.

S.

--
Shevek
I am the Borg.
sub AUTOLOAD { ($s=$AUTOLOAD)=~s/.*:://; eval qq{ *$AUTOLOAD=$s
?sub {$s*&{$s-1}} :sub {1}; }; goto &$AUTOLOAD; } print &{'4'}; 

Reply via email to