in reply to Pass Arrays to a subroutine

I like named params

mysub({ a1 => \@array1, a2 => \@array2 }); sub mysub{ my ( $argref ) = @_; # brackets matter # ref to @array1 is @{ $argref->{a1} } # ref to @array2 is @{ $argref->{a2} }
More examples here

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re^2: Pass Arrays to a subroutine
by stevieb (Canon) on Nov 27, 2015 at 15:00 UTC

    I always used to accept my params within a hashref, but in the last year or so, I've changed to just using a straight up hash instead. I feel it makes the interface a tiny bit cleaner:

    mysub(a => \@array1, b => \@array2); sub mysub { my %params = @_; print "$_\n" for @{ $params{a} }; }