in reply to Re: Last element index with array refs
in thread Last element index with array refs
my $dref = @$list;$dref is a scalar variable, so it imposes scalar context on the right-hand side of the assignment. An array used in scalar context returns the number of elements it contains. That's where your string "8" comes from.
To get what you want, you have to use my ($dref) = @$list; which assigns the first element of the array to $dref. Then you can get the length of this array reference.
If you want to make sure that all the arrays are of the same length your only solution is a foreach loop (or something equivalen). On the other hand, if you are positive that all subarrays have the same length, this method of just looking at the first element works to solve your problem.
-- Hofmator
|
|---|