in reply to pointers == arrayrefs ?
I'm not sure what sort of usage you have in mind, but if you want to count on the "pointer" (memory-address) values of references always being different, this will depend on whether your app happens to create multiple references to the same thing. In it's simplest form, it would involve something like this:
If you test that out, you'll see that only one hash element is created, and the hash value is "second one", because the (stringified) memory-address values of $aref and $anotheref are identical. Of course, there are more convoluted, complicated, circuitous ways to arrive at the same effect (to enhance your debugging experience).my @a = (5..10); my $aref = \@a; #... my $anotheref = $aref; #... my %h = ( $aref => 'first one', $anotheref => 'second one' );
But if you are confident that you are handling only one reference to each distinct array in a script, then there should be no problem with each memory address being a hash key. The only limitation is that you are not able, thereafter, to use the hash keys as references -- that is, you cannot dereference a hash key, because hash keys can be nothing other than strings.
That's why the initial replies pointed you to those CPAN modules, in case you actually want things to "work both ways" in some sense (where references are used as hash keys, and hash keys can still be used as references). But I'd have to wonder about how useful a memory address would be as a hash key... usually, the hash key is something that carries semantic importance relevant to the associated value (if any), or to some aspect of the application. Memory addresses don't have that property.
|
|---|