in reply to Re^2: Question about returning array from sub
in thread Question about returning array from sub

You are returning the array. The array hold references to other arrays, that have to be dereferenced later when you want to access them.

Actually, you should probably return a reference to the main array. If you are just returning it to one caller, which uses it and is done, there's no issue. But it's good practice to pass references around rather than making multiple copies of data.

Your caller will do something like my @bar = function() while &function() is also building up and returning its own array my @foo. Better for the function to return, and the caller to take, a reference to @foo: my $bar = function() and in &function: my @foo = (1,2,3); return \@foo;

Remember: Ne dederis in spiritu molere illegitimi!