in reply to Pass Arrays to a subroutine
As an example, this is one possible way to pass array references to a sub and to use them within the sub.
Update: removed underscores from $a1_ref and $a2_ref variable in initialization to make variable names consistent with the following code lines.my @a = (1, 2, 3); my @b = (5 .. 7); process(\@a, \@b); # pass array references to the sub sub process { my ($a1ref, $a2ref); # retrieve the params my @array1 = @{$a1ref); # dereference $a1ref inti an array my @array2 = @{$a2ref); # ... process @array1 and @array2 # ... }
|
|---|