I think the best way is to use a hash to implement a set by using the existant keys to represent the current members of the set.
My current strategy is along the lines of:
my %set; sub contains($) { return exists $set{$_[0]} } sub add($) { $set{$_[0]} = 1 } sub all($) { return [keys %set] }
(I'm not actually using subs -- just for clarity.)
Is this approach the simplest way?
Is there a better approach avoiding the assignment for the add? Something like create $set{'foo'}?
I think I don't need the hash entries to be defined. I just need them to exist. (If you iterate over keys it will still return entries that have existant but undefined values right?)
-Andrew.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |