Ryan Tate <> wrote:
: If I have an array @array, I can get the last index with $#array.
: What is the equivalent way to get the last index of array reference
: $array?
: I thought $#{@$array} would work, but perl coughed up "Bizarre copy of
: ARRAY in leave at /script.pl line 230."
: Haven't been able to find anything in this in Camel or Google Groups.
Hmm. I thought, "What a cool error message!" and wanted to see what
'use diagnostics' would say about it. So I wrote:
#! /usr/bin/perl
use strict;
use warnings;
my @a=qw(One Two Three);
my $r = \@a;
print "num: ", $#a, "\n";
print "num: ", $#{@$r}, "\n";
__END__
Running it gets:
$ perl foo.pl
num: 2
num: 2
That looks to be working just as you expected it to, doesn't it?
What version of Perl are you using? My 5.6.0 on Linux and 5.6.1 on Win32
both work. 5.8.2 for Cygwin also works. Those are all I have handy
at the moment.
--
Louis Erickson -
-
http://www.rdwarf.com/~wwonko/
Stay away from flying saucers today.