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

the two following bits of code produce to different outputs when the main variable '%args' is viewed with the 'x' command in the debugger.

i'm hoping that someone can explain what i'm seeing.

run a script with the following code

my %args; $args{'expr'} = \['booya' 'kada'];
then perform 'x \%args'...you'll see this:
DB<2> x \%args 0 HASH(0x1cb3778) 'expr' => REF(0x1a35d54) -> ARRAY(0x1ca0124) (WHY AN ARROW?) 0 'booya' 1 'kada'
then run the followin in a script:
my %args; my @ary; @ary = ['booya', 'kada']; $args{'expr'} = \@ary;
in this case 'x \%args' produces:
DB<3> x \%args 0 HASH(0x1cb3778) 'expr' => ARRAY(0x1cb3844) 0 ARRAY(0x1cea068) (WHY A ZERO?) 0 'booya' 1 'kada'
so my question is this: what to the ARROW & ZERO signify and what is the difference. i'm guessing its related to anonymity, but i don't know and i believe there is a gem of knowledge here i don't want to lose.

i suppose a second question is this: where could i have found this answer myself - any documentation that explains debugger command outputs (in detail).

thanks in advance, nebbish

Replies are listed 'Best First'.
Re: using the perl debugger...
by salva (Canon) on Apr 03, 2006 at 19:44 UTC
    you are really creating different structures, Data::Dumper shows the difference clearly:
    $VAR1 = { 'expr' => \[ 'booya', 'kada' ] }; $VAR1 = { 'expr' => [ [ 'booya', 'kada' ] ] };
    I thing you are confused about the way array references are created in perl. Probably, you would like to use...
    my %args; $args{'expr'} = ['booya' 'kada']; # no \ required here
    or
    my %args; my @ary; @ary = ('booya', 'kada'); # use () instead of [] $args{'expr'} = \@ary;
    to create
    $VAR1 = { 'expr' => [ 'booya', 'kada' ] };
Re: using the perl debugger...
by gaal (Parson) on Apr 03, 2006 at 19:50 UTC
    Look at the prints for booya and kada: they have 0 and 1 preceding them. Why? Because those are the indices in an array.

    In the first dump you gave, the container that held a reference to ['booya', 'kada'] had no interesting type of its own, therefore its stringification was REF (ref-to-a-ref). In the second case, you had an array container, and the first element of the array was a reference to ['booya', 'kada']. The second case, with the 0, should be clear: the 0th element of the array pointed to by \@ary is the anonymous array.

    In the second case, there is no index, there's just a straight reference. That is signified by an arrow.

    I think this is the kind of thing you either don't worry about, or deduce, or read the source for. :-)

Re: using the perl debugger...
by nebbish (Novice) on Apr 04, 2006 at 17:32 UTC
    thanks for your input guys. based on that i read more on the () and [] operators, learned how to use data::dumper (pardon the pun), and got that much stronger with references in perl. thanks again, nebbish