[lug] perl :)

j davis davis_compz at hotmail.com
Fri Aug 16 15:31:00 MDT 2002


it looks like i only need to change the operator and apperance number
to tweak this little tid-bit.
jd

>From: Rob Judd <rjudd at mlug.missouri.edu>
>Reply-To: lug at lug.boulder.co.us
>To: <lug at lug.boulder.co.us>
>Subject: Re: [lug] perl :)
>Date: Fri, 16 Aug 2002 10:05:51 -0600 (MDT)
>
>
> > you can't use this trick to find those that appear exactly twice or
> > thrice; it works for "first appearance" because you are dealing with
> > cardinal numbers, which can't go negative.
> >
> > to find elements that appeared a certain number of times, i'd probably
> > do something like this:
> >
> >   my @appears_twice = do {
> >       my %count;
> >       foreach my $elt (@list) { ++$count{$_} }
> >       grep { $count{$_} == 2 };
> >   }
>
>Surely you can use something similar ... won't this work
>
>@twice = grep { ++$count{$_} == 2 } qw(a b a c d d e f g f h h);
>
>to give @twice = qw(a d f h) ?
>
>Cheers, Rob
>
>_______________________________________________
>Web Page:  http://lug.boulder.co.us
>Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>Join us on IRC: lug.boulder.co.us port=6667 channel=#colug


thanks,
jd

jd at taproot.bz
http://www.taproot.bz

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




More information about the LUG mailing list