The one sent in by david which was @uniq{@a} = () was even faster by
a significant margin

where you have

sub using_array {
  
  @uniq{@a} = ();
 
 }

        Need to define my %uniq above as you do my @uniq.

Wags ;)

-----Original Message-----
From: NYIMI Jose (BMB) [mailto:[EMAIL PROTECTED]]
Sent: Friday, August 30, 2002 12:07
To: Felix Geerinckx; [EMAIL PROTECTED]
Subject: RE: uniq elements of an array


Slice is simple and also faster !

Look:

#!/usr/bin/perl
use strict;
use Benchmark;

my @a=qw(a c b c a a b d c c);
my @uniq=();

sub using_grep{
        my %seen=();
        @uniq=sort grep{ ! $seen{$_}++ } @a;
}

sub using_slice{
        my %h=();

        @h{@a}=();
        @uniq=keys %h;
}

timethese (1000000,{ using_grep => \&using_grep,using_slice => \&using_slice
});

__END__

And got:

Benchmark: timing 1000000 iterations of using_grep, using_slice...
using_grep: 29 wallclock secs (28.21 usr +  0.00 sys = 28.21 CPU) @
35447..17/s (n=1000000)
using_slice: 16 wallclock secs (15.80 usr +  0.00 sys = 15.80 CPU) @
63283.13/s (n=1000000)


José.



-----Original Message-----
From: Felix Geerinckx [mailto:[EMAIL PROTECTED]] 
Sent: Friday, August 30, 2002 8:39 PM
To: [EMAIL PROTECTED]
Subject: Re: uniq elements of an array


on Fri, 30 Aug 2002 18:26:03 GMT, Tom Allison wrote:

> david wrote:
>> @hash{@all_elements} = ();
>> 
>> now "keys %hash" gives you the unique elements.
> 
> Would these exist but be undef?
> 
> 

Why don't you write a little program to try it out, using the aptly named
'exists' and 'defined' functions?

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



**** DISCLAIMER ****

"This e-mail and any attachment thereto may contain information which is
confidential and/or protected by intellectual property rights and are
intended for the sole use of the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to,
total or partial reproduction, communication or distribution in any form) by
other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either
by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our
website at http://www.proximus.be or refer to any Proximus agent.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to