in reply to Directly Dereferencing an Array Reference to an Array
Turning on strict and warnings helps a boodle.
Converting your code to
gives me#!/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;
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.
This will give us the result we desire.@{$selects[0]}
Hope this helped,
-v.
|
|---|
| 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 |