Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A LOGIC QUESTION

Status
Not open for further replies.

iggit

Programmer
May 20, 2001
47
US
I have an array split by pipes sitting in @playerhistory , fields are $username,$enginenumber,$date,$time,$gamenumber,
and $rollnumber.

The total count of all entries is $totalrolls++

I can't nest a comparative function to shrink the list to a unique count of individual users instead of the total count of user lines due to the size of the flat file.

So the question is, how do I count just the unique usernames? In a snippit that won't drain the system of all life?

Any takers please?

Thanks for your help in advance.
 
OK I haven't lost it completely.
Sorry for posting this so quickly.
The answer was staring me in the face.
if ($alreadyfound =~ /$username/)
} else {
$totalplayershistory++;
}
$alreadyfound = "$username,$alreadyfound";

Sorry for taking up the space.
 
There a couple of problems with doing it the way that you came up with. One minor, one potentially major.

The minor issue is that the regex search is going to get slower and slower as you have more and more names. It'll probably never be truly significant for any individual lookup, but you'll be doing it for every name, so it could ultimately be very noticable.

The more serious problem is that a file looking like:
[tt]bobsmith,....
bob,....[/tt]

will not get [tt]bob[/tt] since the regex [tt]/bob/[/tt] will match the "bob" in "bobsmith".

There are, of course, many ways to do this. The way that I generally choose is to use a hash to indicate names that have been seen. This makes lookups very quick and resolves the second problem nicely.

[tt]if (!exists $alreadyFound{$username}) {
$totalplayershistory++;
$alreadyFound{$username} = 1;
}
[/tt]
 
Thank you very much. Was hoping to eliminate the major problem by searching for email addresses which would not be duplicated. The method you used is far superior to what I came up with so thank you I will indeed use it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top