in reply to Unique numeric ID for reference?

Jeffrey Kegler and then pull out the hex number with a regex, but I'm in a context where speed is a big deal. I

As shmem pointed out, refaddr is 5.8.8 core (Scalar::Util)

Otherwise, you could do that by hand, like:
my @array = (1,2,3,4); my $ref = \@array; my $addr = hex +($ref=~/(?<=\()[^)]+/g)[0];
Which should not *that* slow, especially if you
do big business with GRT.

To get the complete ref string back, do a simple:
my $rs = sprintf "ARRAY(0x%x)", $addr;
My question: why can't you take the whole
"ref" string, including "Array(...)"?

Regards

mwa

Replies are listed 'Best First'.
Re^2: Unique numeric ID for reference?
by Jeffrey Kegler (Hermit) on Oct 07, 2007 at 00:23 UTC

    The competition is an indexed dereference, and my guess is a regex has to be slower than that.

    In any case, Juerd's pointing out that all I needed to do was force the reference to numeric (duh! I feel so dumb) seems to settle the matter.

    As for just using the string, the GRS transform means putting it into a sortable pack() string. There's more than one reference in the sort key, and a couple of ordinary numerics and a Boolean as well. Since the strings are variable length they require a little bit of trickery to pack and they are longer than integers. I also wonder if stringify'ing doesn't have a higher cost than forcing to numeric.

    For yucks, I probably should Benchmark the choices, but if anything beats Juerd's suggestion, I'll be a little stunned.

    jeffrey