in reply to Re: Re: Re: Re: Reference to a sub return / Config::General
in thread Reference to a sub return / Config::General
So I'm not only running into the difference between a value and a variable, but also the difference between a list and an array.
Right. The only way you can really return an array itself (or, as previously discussed, a hash) is with a reference. Just like with return %hash, when you write return @array, the array is flattened. The elements are sucked out and put into a list. The list is returned. The caller can then grab that list and do what it wants with it; be it iterate through it, suck it into a new array, or even suck it into a hash.
It may seem complex at first, but really it's very simple. Your data structures get dismantled unless you use references.
Before you dismay at what happens to multi-level datastructures, keep in mind that these are only achievable in Perl via the use of references. They're perfectly safe, so things like @array = ([qw/one two/], [qw/three four/]); return @array will not blow up into tiny pieces. 8^)
|
|---|