>>>>> "SF" == Steve Fink <[EMAIL PROTECTED]> writes:
SF> I don't think this has been mentioned, although it's really just a SF> combination of two existing ones: I often have a table of sets. SF> for my $user (@filenames) { SF> open(my $fh, "<", $user) { SF> while(<$fh>) { SF> $use{$user}{$1} = 1 while /include\s*['"](.*?)['"]/g; SF> } SF> } SF> It's a full graph, with fast looking and iteration over outgoing edges. i consider graphs a variant of deep (and cyclical) data structures. and i think they are more complex than the other simple hash uses. also graphs are too hard to explain in one slide for this class. but i will keep it in mind as another use. all the classic linked list structures can be easily done with hashes for sure. SF> There's sort of another use buried in there, too: hashes can be SF> used to map object identifiers to their data (a la inside-out SF> objects or something simpler that is just trying to keep the real SF> data in a canonical place, perhaps to avoid worrying about cyclic SF> references.) i use a hash to track all objects created by a class. the fun part is that the key and value were the same thing. but the key gets stringified which is why you still need the ref/object as the value. SF> Hashes can be used for caches or memoization: SF> our $answer; SF> sub func { SF> return $answer ||= ...compute...; SF> } caching is a good one. that is all that memoize uses. SF> Hashes can be used for sparse arrays: SF> $arr{10} = "X"; SF> $arr{83719} = "Y"; i mentioned that one. SF> Hashes can be used for symbol tables. :-) true. i didn't mention that. but i always teach to use hashes for data and not the symbol table (via symrefs). mung the symbol table only when you need to mung it! thanx, uri -- Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org