I could not understand that there was a problem with the code you quoted, so I wrote a short test script and passed it through Perl.
#! perl use warnings; use strict; my $allDirArray = [{dir => "b"},{c => "d"}]; my $i = 0; my $tempDir = ${$allDirArray}[$i]{'dir'}; print "$tempDir\n";
As stated above, using Perl 5.10 in Cygwin, the program ran as follows:
$ perl allarraydir.pl b
The error message was not printed. See http://codepad.org/pH4eyMlt
Edit
After including the telemachus offer, I added the following code at the end of the above program,
# The following addition was included re telemachus comment my @allDirArray2 = ({dir => "b"},{c => "d"}); $tempDir = ${$allDirArray2}[$i]{'dir'}; print "$tempDir\n";
ran it again and received the following error message:
$ perl allarraydir.pl
Global symbol "$ allDirArray2" requires explicit package name at
allarraydir.pl line 10.
Execution of allarraydir.pl aborted due to compilation errors.
(This should be a comment on your question, not an answer, but the code is too long.)
user181548
source share