Stuart White wrote: > > > In the end, I want @SAN to have all the unique > > names > > > within the file. Any ideas? > > You just described a Hash. Use %hash and then > > either uppercase or lowercase the the incoming key. > > YOu could then add a count to the Hash so you know > > you are looking at all things or not. The keys for a > > hash can only appear once(ie, San and SAn are two > > different keys) that is why you should uppper or > > lower the keys. > > > > Wags ;) > > If I had a hash, I'd have to have a key and a value > though.
If you are counting the strings as they are found, there is a relevant value--the count. If not, there is still a value, found [true = 1, false = undef or 0] associated with it. This is the standard Perl way toguarantee uniqueness. my $found = {}; my %count = (); foreach (@big_bag) { $found->{$_} = 1 unless $found->{$_}; $count{$_}++; } > I'm just looking for one or the other. I > suppose I could have key value pairs in the %SAN hash > like so: > > Parker:san > Bowen:san > etc > Then I'd probably stick all of the keys into an array. > However, using a hash I wouldn't have to use a foreach > loop or an unless, would I? Huh? Use a foreach loop to accomplish what purpose? You can definitely access any given element in a hash without iterating through the structure for it. The internal implementation of a hash access is an O(1) process. That is, there is no particular penalty for size of container. This is another good reason to use hashes in such cases. The even better reason in this context is that hashes have uniqueness of keys built into their design, while arrays do not. > That would make the > Parker:san format and then dumping the keys into an > array worth it. You lost me here. Instead of speaking in terms of program structures, can you describe your problem in terms of what information you wish to produce out of this? What form does the data take coming in? What is the form of the desired output information? I see you getting yourself boxed in a lot by premature selection of data structures. Much better to describe the problem clearly in plain language first. The appropriate data structures can be settled on after you develop your overall plan of action. Okay, I just read the other branch of this thread, and it look like you want to extract a simple list of the players names, with no duplicates. Wow, this has been some merry-go-round for an essentially simple problem. Without the premature focus on program structures, it would have been quickly resolved. A clear and simple specification will take you much farther than even the most clever coding trick. Focus on the logic. The code will follow. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>