I think you're looking at this the wrong way.  What you want is to fill
two arrays with data from a function.  This does not necessarily mean
that you want the function to return two arrays (it can't actually be
done, since the function will flatten them both out into one list when
it returns them).  The best solution is probably to pass a reference to
the arrays you want filled.

I think this will do what you want:

######################################

#DECLARE THE ARRAYS
my (@array1,@array2);

#POPULATE THE ARRAYS
func([EMAIL PROTECTED],[EMAIL PROTECTED]);

#PRINT THE CONTENTS OF @array1
print '@array1'."\n";
foreach(@array1){
   print "\t$_\n";
}

print "\n\n";

#PRINT THE CONTENTS OF @array2
print '@array2'."\n";

foreach(@array2){
   print "\t$_\n";
}


#THE FUNCTION THAT POPULATES THE ARRAYS
sub func{
   #THESE ARE THE REFERENCES
   my($ref1,$ref2) = @_;

   [EMAIL PROTECTED] IS THE ARRAY THAT $ref1 REFERS TO
   @{$ref1} = (1..20);
   push(@{$ref1},"twenty-one");

   @{$ref2} = (22..40);
   push(@{$ref2},"forty-one");
}

#######################################

-----Original Message-----
From: Khairul Azmi [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 03, 2005 5:22 PM
To: beginners@perl.org
Subject: functions that returns two arrays

Hi,
I'm trying to write a function that could return two arrays.

[Tim Johnson] <snip>


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to