What does the hexadecimal number in a reference to an array, hash, etc. indicate?

StackOverflow https://stackoverflow.com/questions/4576686

  •  14-10-2019
  •  | 
  •  

Question

When printing a reference to an array, hash, etc, what is that hexadecimal number in brackets?

perl -e 'print []'

Gives an output like: ARRAY(0x9acb830)

What is 0x9acb830 exactly? If I print the same ref again, this number changes.

Was it helpful?

Solution

If you print the same ref again the number should remain the same; the number is the actual address of the SV header for the referred to thingy.

OTHER TIPS

It's basically the memory location of the array. Perl is trying to let you know you're trying to print a reference and not a scalar value.

Try this:

#! /usr/bin/env perl
use strict;
use warnings;

my @foo = qw(one two three four five);
print @foo . "\n";   #Prints the array in a scalar context (five items)
print \@foo . "\n";
print $foo[1] . "\n";
print \$foo[1] . "\n";

5
two
SCALAR(0x100804ff0)
ARRAY(0x10082ae48)

Notice that when I print a reference, Perl tries to do the right thing. Instead of attempting to print some strange value, it tells you that you're trying to print a scalar or array reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top