in reply to Using stringified refs for unique IDs?

First off, chip++ for that code.

I had always heard that you can't use references as keys, but nobody said you can't use the string that represents the reference as a key. So, for a naive test, i tried this:

use strict; my %TEMPS; my $max = 1_000_000; Foo->new() for (0..$max - 1); print "ok\n" if $max == scalar keys %TEMPS; package Foo; sub new { my $self = {}; $TEMPS{ $self->{ID} = "$self" } = $self; return $self; }
My reasoning was that if the number of objects i created equals the number of keys in the hash that contains them, no duplicate id's were used. The result was "ok" ...

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)