--- Wagner Jeff Civ Logicon/TTMS <[EMAIL PROTECTED]> wrote:
> Let me see if I understand your one-liner...
> 
> *  the "map" function creates a hash, using the array elements as key
> names, automatically eliminating duplicates
> *  the output from the "keys" function (an array) is compared to the
> original array, both in scalar context, so the number of elements
> will be different if there were duplicates

You've got the gist of it. There are a few technicalities that are
imprecise, but that's the idea, and they are gearhead points. Do you
want the technical corrections, or were you just making sure you could
follow the code? (They're nit-picky =o)  For example, keys returns a
list, not an array.....

> Pretty neat.  So the difference between this an the iterative
> approach is that the one liner processes all the array elements every
> time and the iterative approach drops out as soon as it finds a
> duplicate.

Mainly. =o)
Good job.
 
> -----Original Message-----
> From: Bob Showalter [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 31, 2001 09:03
> To: '[EMAIL PROTECTED]'
> Subject: RE: check array element (HELP)
> 
> 
> > -----Original Message-----
> > From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] 
> > Sent: Tuesday, July 31, 2001 9:44 AM
> > To: [EMAIL PROTECTED]
> > Subject: RE: check array element (HELP)
> > 
> > 
> > I would probably do this, although i'm sure some smarty-pants 
> > could come up with a one-liner  ;)
> > 
> > sub repeated_elements
> > {
> >     my %found_one;
> >     for (@_)
> >     {
> >             return 1 if $found_one{$_}++;
> >     }
> >     return 0;
> > }
> 
> One-liner:
> 
>    print "Duplicates!" if keys %{{ map { ($_ => 1) } @arr }} != @arr;
> 
> Note: Do NOT use this! Along with being quite unreadable, it's also
> inefficient. Use the iterative approach above.
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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

Reply via email to