Thanks Sudarshan, Felix....!! This is one of the area that I never had to look. But as 
the saying goes...curiosity kills the crow...I am now all into it!!

Thanks again!!   

-----Original Message-----
From: Felix Geerinckx [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 01, 2002 10:02 AM
To: [EMAIL PROTECTED]
Subject: RE: Obtaining a slice of unique values from an array


on Mon, 01 Jul 2002 13:45:30 GMT, [EMAIL PROTECTED] (Shishir 
K. Singh) wrote:

> This is the example "d" cited in perldoc -q duplicate
> d)  A way to do (b) without any loops or greps:

[line numbers added for reference]
 
>     01    undef %saw;
>     02    @saw{@in} = ();
>     03    @out = sort keys %saw;  # remove sort if undesired
> 
> I am a bit confused about this example ?? 

You need to learn about hash-slices, e.g. from Uri Guttman's article 
at

    <http://tlc.perlarchive.com/articles/perl/ug0001.shtml>

What's happening?
 line 01 makes sure you start with an empty hash
 line 02 creates a key-value pair in %saw foreach element of @in. The 
         value is undef (because of the '()' on the rhs, but who 
         cares ;-). The essential part here is that a hash cannot 
         have duplicate keys.
 line 03 puts the keys (which are unique by definition) in @out

-- 
felix




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