in reply to list references

The problem you are dealing with is context.

$ref=\(1..3);

This is in a SCALAR context .. it evaluates the list, and gets the value "3". It assigns a REFERENCE to this value to $ref. Hence $$ref will have the value 3.

To get an ARRAY, to do what I think you want, try this:

$ref = [1..3];

This generates an anonymous array REFERENCE , pointing to the array (1,2,3), and assigns that to $ref.

@$ref now is an array (1,2,3).

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarantees offense.

Replies are listed 'Best First'.
Re^2: list references
by sleepingsquirrel (Chaplain) on Jun 15, 2004 at 23:48 UTC
    I'm beginning to think this is some sort of bug. Here's what I get for your example...
    greg@sparky:~/test$ perl -e '$ref=\(1..3); print $$ref' Not a SCALAR reference at -e line 1. greg@sparky:~/test$ perl -e '$ref=\(1..3); print "@$ref\n"' 1 2 3


    -- All code is 100% tested and functional unless otherwise noted.
      Yes - that DOES look strange.
      Here is what I get on my " perl, v5.8.3 built for MSWin32-x86-multi-thread"
      C:\> perl -e "$ref=\(1..3); print $$ref" 3 C:\>perl -e "$ref=\(1..3); print qq(@$ref\n)" Not an ARRAY reference at -e line 1. C:\>perl -e "$ref=[1..3]; print qq(@$ref\n)" 1 2 3

      Offense, like beauty, is in the eye of the beholder, and a fantasy.
      By guaranteeing freedom of expression, the First Amendment also guarantees offense.