You just have to be careful how you return them. An array is returned as a list of items, for instance, and Perl can't figure out where the list ends if you don't pass the array last:my ($hashref, $arrayref, @array) = new(); print $hashref->{'a'}; print $array[0]; print $arrayref->[1]; sub new { my $hashref = {'a' => '1'}; my @array = (2,3); my $arrayref = [4,5]; return ($hashref, $arrayref, @array); }
For this reason, it's generally safer to pass arrays only via reference. Passing via reference is more efficient anyway, especially when working with large arrays.## $arrayref isn't defined! my ($hashref, @array, $arrayref) = new(); print $hashref->{'a'}; print $array[0]; print $arrayref->[1]; sub new { my $hashref = {'a' => '1'}; my @array = (2,3); my $arrayref = [4,5]; return ($hashref, @array, $arrayref); }
In reply to Re: On Perl Objects!
by TedPride
in thread On Perl Objects!
by newbio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |