Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jul 2002 21:28:31 -0300 (ART)
From:      Fernando Gleiser <fgleiser@cactus.fi.uba.ar>
To:        "Christopher J. Umina" <uminac@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com>
Cc:        FreeBSD Question Mailing List <questions@FreeBSD.ORG>
Subject:   Re: checking if something is already in an array
Message-ID:  <20020730212213.G6656-100000@localhost>
In-Reply-To: <20020730170022.H81391-100000@216-164-225-145.c3-0.wth-ubr2.sbo-wth.ma.cable.rcn.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020730212213.G6656-100000>