From owner-freebsd-questions Tue Jul 30 17:30:58 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D0EB337B400 for ; Tue, 30 Jul 2002 17:30:53 -0700 (PDT) Received: from cactus.fi.uba.ar (cactus.fi.uba.ar [157.92.49.108]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C3D243E42 for ; Tue, 30 Jul 2002 17:30:52 -0700 (PDT) (envelope-from fgleiser@cactus.fi.uba.ar) Received: from localhost (localhost [127.0.0.1]) by cactus.fi.uba.ar (8.11.6/8.11.6) with ESMTP id g6V0SVr07574; Tue, 30 Jul 2002 21:28:32 -0300 (ART) (envelope-from fgleiser@cactus.fi.uba.ar) Date: Tue, 30 Jul 2002 21:28:31 -0300 (ART) From: Fernando Gleiser X-X-Sender: To: "Christopher J. Umina" Cc: FreeBSD Question Mailing List Subject: Re: checking if something is already in an array In-Reply-To: <20020730170022.H81391-100000@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com> Message-ID: <20020730212213.G6656-100000@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 30 Jul 2002, Christopher J. Umina wrote: > Hi all, > > I'm really stupid lately with Perl and stuff, but I got this list > of screen names and I made it into an array in perl called @sns. I want > to count the amount of times each name shows up in that array and I want > to make an array of each name in the original array, but only occuring > once. Use a hash. That's what they are for =0) for $key (@sns) { $hash{$key}++; } # # $hash{$key} says how many times $key is in @sns # If you want an array with the keys of the hash, just say: @keys=keys(%hash); Read perldata(1) for further details on hashes and arrays Hope this helps Fer > > adarc22 > adarc22 > adarc22 > adarc22 > alldayyesterday > alldayyesterday > babygurl2835 > babygurl2835 > bctictac8 > bctictac8 > beth42085 > cc skillet > ccgirl436 > ccgirl436 > devilchik205 > dublindamien > e is happy > e is happy > fritzilldo > ilaughatyourlife > jea9f2oo3 > katsie236 > kelzy16 > lauren md 6 9 > mastahuy85 > meikman99 > meikman99 > reggie645 > reggie645 > reggie645 > reggie645 > reggie645 > reggie645 > reggie645 > russh2112 > russh2112 > sllissa85 > superman lmd 69 > > ...is my original array but I want a new array with each name in this > array appearing only once and count each name's occurance in an additional > array, even a 2d array works. (if you can do that in Perl...?) > > Thanks a lot, > Christopher J. Umina > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message