SPUG: Fw: Uniq in perl

Bill Campbell bill at celestial.com
Sat Mar 17 14:44:09 CST 2001


On Wed, May 16, 2001 at 06:28:44PM -0700, Richard Anderson wrote:
>Does anyone have comments for Mike?

I think this would do it (assuming that the job is to resort the
array in place).

sub uniq {
	my %work = map{$_, 1} @_;
	@_ = (keys %work);
}

>Richard Anderson, Ph.D.          www.unixscripts.com
>Perl / Oracle / Unix                Richard.Anderson at raycosoft.com
>Raycosoft, LLC                        Seattle, WA, USA
>----- Original Message ----- 
>From: "Mike" <shivan at ici.net>
>To: "Richard Anderson" <Richard.Anderson at raycosoft.com>
>Sent: Friday, March 16, 2001 2:12 PM
>Subject: Uniq in perl
>
>
>> This is something I had sitting around. I didn't write it. Its a subroutine 
>> that uniqs an array. I was just wondering if this is the best way to do it 
>> or if anyone has any thing better. Thanks
>> 
>> 
>> ## Usage: &uniq( \@ARRAY );
>> sub uniq {
>> my (@uwork, @unew, $uname);
>>    @uwork = @{$_[0]};
>>    @uwork = sort( @uwork );
>>    @unew  = ( shift @uwork );
>> 
>>    foreach $uname ( @uwork ) {
>>       @unew=( @unew, $uname) if ( $uname ne $unew[ -1 ] );
>>    }
>> 
>>    @{$_[0]}=@unew;
>> }
>> 
>> :wq
>> 
>> 
>
>
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
>  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>

-- 
Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

Once at a social gathering, Gladstone said to Disraeli, ``I predict,
Sir, that you will die either by hanging or of some vile disease''.
Disraeli replied, "That all depends upon whether I embrace your
principles or your mistress".

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list