in reply to Re: Using hashes for set operations...
in thread Using hashes for set operations...
In Perl stringification of references has no performance penalty. It's just a string with the reference addressą and the type (this includes package name if blessed).
perl -e '$p=[];print $p' ARRAY(0x928c880)
(I think you are confusing with other language like JS˛, where the whole data is dumped)
OTOH, there is a doubled memory consumption when using primitive scalars like long strings.
>As for getting a fake "" key you need to toss out, I don't think that's a problem if you make sure that the stringification never returns "" for a valid item in the set.
well I think a special case handling "" wouldn't cost too much performance...it's just not elegant anymore.
> Ultimately, I think the answer to "how do I find an intersection" isn't to repeat some incantation invented by someone else, but to simply call intersection. The algorithm should be canned in a CPAN module.
There is already Set::Object which seems to follow the same ideas, but it looks heavy and uses inline C...
Anyway my point was first to improve the FAQ and then thinking about a module.
Cheers Rolf
1) Of course one should be careful when mixing strings and references in one set... :)
2) e.g. javascript:a=[1,[2,3]];alert(a) shows 1,2,3