in reply to Directly Dereferencing an Array Reference to an Array

Turning on strict and warnings helps a boodle.

Converting your code to

#!/usr/bin/perl use strict; use warnings; my @temp = (2,3,4); my @selects; $selects[0] = [@temp]; my $refdates = $selects[0]; #my @workdts = @$refdates; my @workdts = @$selects[0]; print "$_\n" for @workdts;
gives me
Global symbol "$selects" requires explicit package name at ./p line...

Now since we explicitly declared @selects as an array, then $selects[0] should be an array element, which it is, and we only need to cast that reference to an array type.

Well, since @ binds tighter than subscripting, the compiler thought we were trying to use @$selects, which implies that $selects, the scalar, exists. Since it doesn't, we need to enforce what we want with braces.

@{$selects[0]}
This will give us the result we desire.

Hope this helped,
-v.

"Perl. There is no substitute."

Replies are listed 'Best First'.
Re^2: Directly Dereferencing an Array Reference to an Array
by samizdat (Vicar) on Aug 30, 2006 at 17:59 UTC
    Many thanks!
    Before I get heaped with an OD of ashes, the reason I don't have strict and warnings on is that this is embperl code embedded in a web page. Embperl does things (such as loading once with [! !]) which do not fare well under strict pragmas.

    Don Wilde
    "There's more than one level to any answer."