in reply to Simple Array

I would use something similar to what swiftone has written, but I would populate the hash directly and skip the array:
while (<STDIN>) { $some_hash{$_}++; }
The value of each key is the numer of entries in the list. If you need to iterate over the list, you use something like this:
foreach (keys %some_hash) { ...some code here... }
If you maintain a seperate list and hash, you have to update both if one changes. With this method, you only need to track one and thus have an easier maintenance job. The drawback is you lose ordering on the list, but since we have user entered data, this ordering may not matter. If necessary, you could try to keep order with the following (untested) code:
my $position = 1; while (<STDIN>) { $myhash{$_}{'item'}++; $myhash{$_}{'position'} = $position++ if ! exists $myhash{$_}{'pos +ition'}; }

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

Replies are listed 'Best First'.
RE: (Ovid) Re: Simple Array
by geektron (Curate) on Sep 12, 2000 at 02:17 UTC
    i use code like this all the time. but be careful - you may get results that shouldn't be duplicate ( like smith and Smith, which in your context may be the same.)

    depending on your usage, some preprocessing may be in order.