purnak has asked for the wisdom of the Perl Monks concerning the following question:

Is there any information (at all) that you can infer by looking at a PERL array reference?

I mean information like 32/64 bit system architecture or anything like that.. or is it just a hex address with no real meaning.

.  Lets take an example of an array reference as ARRAY(0x9458b48)

Replies are listed 'Best First'.
Re: what do you infer from an array reference?
by Eily (Monsignor) on Feb 06, 2017 at 10:44 UTC

    Although the hex value is an address, there's no easy way to use it as such, and no way at all using pure Perl (you can't turn a string "ARRAY(0x9458b48)" back into a reference, even if the address is valid). The actual use is that the address is unique, and makes it possible to check that two variables hold a reference to the same array: $ref1 eq $ref2, or $ref1 == $ref2. In the first case, the string including the type and address will be used, and in the second case, only the address is used (but there can't be two different values with different types sharing an address).

    In the end, this value should be treated as a random unique id for your references, you can't use it to know which variable was allocated first, you can't use it accross calls to perl to check that you have the same data.

Re: what do you infer from an array reference?
by Corion (Patriarch) on Feb 06, 2017 at 07:51 UTC

    The hex number in the reference is the memory address of the AV structure the RV points to.

Re: what do you infer from an array reference?
by kcott (Archbishop) on Feb 07, 2017 at 00:01 UTC

    G'day purnak,

    Years ago, when working on 32-bit systems, I used to get hexidecimal numbers (such as you posted: 9458b48) that would fit into 32 bits. Now, on a 64-bit system, I get hexidecimal numbers that won't fit into 32 bits (but will fit into 64 bits):

    $ perl -E 'say []' ARRAY(0x7fd8278040b0)

    Of course, 9458b48 will also fit into 64 bits. I'd be very wary of making any inferences regarding the system architecture based on the hexidecimal number.

    Although you only asked about array references, there are many other types of references, that follow the same pattern. Here's some examples:

    $ perl -E 'say for [], {}, \"", sub {}' ARRAY(0x7ff6d60040b0) HASH(0x7ff6d602bf70) SCALAR(0x7ff6d602c948) CODE(0x7ff6d602c960)

    The ref function has a more complete list; perlref has, in its own words, "complete documentation about all aspects of references".

    Finally, as an adjunct to ++Eily's reply, here's a recent post where the equality of references was used.

    — Ken

      Thanks Ken.. This was informative.