How do I determine the number of elements in an array reference?
That would be:
scalar(@{$perl_scalar});
You can get more information from perlreftut.
You can copy your referenced array to a normal one like this:
my @array = @{$perl_scalar};
But before that you should check whether the $perl_scalar
is really referencing an array, with ref
:
if (ref($perl_scalar) eq "ARRAY") { my @array = @{$perl_scalar}; # ...}
Update
The length
method cannot be used to calculate length of arrays, it's for getting the length of the strings.