#!/usr/bin/perl -w
use strict;
# This won't work:
my (@a,@b) = getlists_1();
print "getlists_1: A ( @a ) and B ( @b ) \n";
# Instead, pass by reference:
(*a,*b) = getlists_2(\@a, \@b);
print "getlists_2: A ( @a ) and B ( @b ) \n";
# ------------------------------------------------------------------
# From 'man perlsub':
# If you return one or more aggregates (arrays and hashes), these will be
# flattened together into one large indistinguishable list.
# ------------------------------------------------------------------
sub getlists_1 {
my @foo = (1,2,3);
my @bar = (4,5,6);
return @foo,@bar;
}
sub getlists_2 {
my ($foo, $bar) = @_;
@$foo = (1,2,3);
@$bar = (4,5,6);
return ($foo,$bar);
}
In reply to Re: Returning two lists from a sub
by Anonymous Monk
in thread Returning two lists from a sub
by cormanaz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |