On Mon, 1 Apr 2002, Allison Ogle wrote:

> I don't know how long the list is and eventually in the list some of
> the names will repeat.  I want to put these names in an array but I
> don't want to repeat any names in the array and I want to keep a count
> of how many times the name appears in the list.  Does anyone have any
> ideas or suggestions?  Thanks,

This is based on one of the FAQ's.  @array1 is your array of names. (See
http://www.perldoc.com/perl5.6.1/pod/perlfaq4.html, Data:Arrays, under
the heading "How do I compute the difference..."):

%count = ();
foreach $element (@array1) { $count{$element}++ }

Your array of unique names is now available from the keys of %count; the
number of occurences of each unique name is available as the value of
%count{$name}.

best,
Eric

-- 

James Eric Lawson
Research Publications Editor
National Simulation Resource

[EMAIL PROTECTED]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Whereof one cannot speak, thereof one must be silent. -- Wittgenstein


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

Reply via email to