in reply to Re: Reference on List & Arrays Difference
in thread Reference on List & Arrays Difference

You wrote about this bit of code
$l_ref = \(1,2,3,4);

A list is not a perl data type, it's just some grouping of elements, so you can't create a reference to that. You can only take a reference to what comes out of evaluating that grouping expression, which is not an array in your case, ...

Correct, and well said.

... but the number of elements inside the list.

That's wrong. It's (a reference to) the last of the scalar expressions that were strung together with the scalar comma operator. Changing the code to

$l_ref = \(1,2,3,99);
makes the difference apparent.

Anno

Replies are listed 'Best First'.
Re^3: Reference on List & Arrays Difference
by shmem (Chancellor) on Mar 11, 2007 at 14:05 UTC
    Oh..! Thanks for correcting that. So the (1,2,3,4) is not even interpreted as a list, but as a grouping of operands and operators which evaluation results in the last (rightmost) operand.

    You never stop to learn...

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Exactly! As the saying goes: There is no list in scalar context.

      Anno

Re^3: Reference on List & Arrays Difference
by jwkrahn (Abbot) on Mar 11, 2007 at 22:08 UTC
    To elucidate further, \( 1, 2, 3, 4 ) is just short for ( \1, \2, \3, \4 ):
    $ perl -le' use Data::Dumper; @x = \( 4, 5, 6, 7 ); print Dumper \@x; ' $VAR1 = [ \4, \5, \6, \7 ]; $ perl -le' use Data::Dumper; @x = ( \4, \5, \6, \7 ); print Dumper \@x; ' $VAR1 = [ \4, \5, \6, \7 ];
    And the assignment to a scalar does the same thing with or without the backslash(es):
    $ perl -le' use Data::Dumper; $x = ( 4, 5, 6, 7 ); print Dumper $x; ' $VAR1 = 7; $ perl -le' use Data::Dumper; $x = \( 4, 5, 6, 7 ); print Dumper $x; ' $VAR1 = \7; $ perl -le' use Data::Dumper; $x = ( \4, \5, \6, \7 ); print Dumper $x; ' $VAR1 = \7;