in reply to Re: Returning multiple arrays
in thread Returning multiple arrays
There's a subtile mistake in your code. You're improperly dereferencing $array_a and $array_b. Yes, it's working for you ok, but consider the following code:
perl -we "@array = qw/one two three/; print @array[1], $/;"
And the warning is...
Scalar value @array[1] better written as $array[1] at -e line 1.
Why? Because @array[1] is an array slice of exactly one element. It's similar to @array[0 .. 3], except for being just one element. Perl prefers (for various good reasons) that you use slice semantics when you intend a slice, and scalar semantics when you mean a single element of an array.
Now, why doesn't your example throw a warning? Because you're dealing with references, not simple arrays. I suppose nobody's thought to add such a warning to Perl's repertoire yet, but it probably ought to be there.
The proper way to dereference $array_a would be like this:
print $array_a->[0];
Hope this clears up a potential future mistake... ;)
Dave
|
|---|