in reply to Subroutine Return Problem
#!/usr/bin/perl -w use strict; randarrays(); # Sub to create two arrays with 5 random elements sub randarrays { my (@a1,@a2) = (); push @a1, (int rand 1000) for (1..5); push @a2, (int rand 1000) for (1..5); printarray(\@a1,\@a2); # \@ makes the call pass by reference. } # print the arrays sub printarray { my ($array1_ref, $array2_ref) = @_; # read the refrences into sc +alars print "array 1\n"; print +($_,$/) for (@{$array1_ref}); # @$ derefrences print $/; print "array 2\n"; print +($_,$/) for (@{$array2_ref}); }
output
array 1 610 509 548 628 370 array 2 802 249 464 312 381
NOTE: the output might change on your machine as they are supposed to be random
|
|---|