> Date: Mon, 26 Mar 2007 04:31:09 -0700
> From: Bill Luebkert <[EMAIL PROTECTED]>
> Subject: Re: unique function?
> To: ukhas jean <[EMAIL PROTECTED]>
> Cc: Active Perl <[email protected]>
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> ukhas jean wrote:
> > Hello,
> > 
> > I have an list of version nos. (some version nos. being repetitive) 
... 
> > like for eg.
> > @arr = qw{7.2.0.6 7.2.0.5 7.2.0.6 7.2.0.5 7.2.0.6};
> > 
> > I want to get only the unique values in @arr. i.e. version nos. 
7.2.0.6 
> > and 7.2.0.5
> > is there an inbuilt perl-function that does this??
> > 
> > (PS: I have done this using for and if-loops; but was wondering if 
there 
> > was an easier way)
> 
> How about just using a hash:
> 
> my @arr = qw{7.2.0.6 7.2.0.5 7.2.0.6 7.2.0.5 7.2.0.6};
> my %h = ();
> ++$h{$_} foreach @arr;
> print "$_\n" foreach sort keys %h;
> 
> 
Here an another solution:

@[EMAIL PROTECTED]('init') x @arr;

print "$_ value: $myhash{$_} \n" foreach sort keys %myhash;

Regards Michael




----------------------------------------------------------------------------------------------------------------------------------------------
 
FIDUCIA IT AG 
Fiduciastraße 20 
76227 Karlsruhe 

Sitz der Gesellschaft: Karlsruhe 
AG Mannheim HRB 100059 

Vorsitzender des Aufsichtsrats: Erwin Kuhn 
Vorsitzender des Vorstands: Michael Krings 
Vorstand: Klaus-Peter Bruns, Hans-Peter Straberger, Eckhardt Werner 

Umsatzsteuer-ID.Nr. DE143582320, http://www.fiducia.de 
----------------------------------------------------------------------------------------------------------------------------------------------
 
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to