What does the hexadecimal number in a reference to an array, hash, etc. indicate?
When printing a reference to an array, hash, etc, what is that hexadecimal nu开发者_开发问答mber 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.
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.
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.
精彩评论