in reply to subroutine - Passing Array Reference by Reference

In your case, if someone says passing by reference, it usually means:

foo($arrayRef);

As $arrayRef is a reference already. In the same sense, if you have @array, then you:

foo(\@array);

If you don't want to pass by reference, you just:

foo(@array);

Replies are listed 'Best First'.
Re^2: subroutine - Passing Array Reference by Reference
by gargle (Chaplain) on Oct 30, 2005 at 07:12 UTC

    Maybe offtopic but keep in mind that when passing more than one parameter the parameter list will be flattened. You do need references in that case to distinguish between the items in your parameter list!

    The following code doesn't consider the two different arrays, it only sees one long parameter list.

    #! /usr/bin/perl use strict; use warnings; my @array1 = ( 1, 2, 3, 4, 5); my @array2 = ( 1, 2, 3, 4, 5); list(@array1,@array2); sub list { foreach my $c (@_) { print $c . " "; } }

    The following code only expects references and will treat each reference as an array reference.

    #! /usr/bin/perl use strict; use warnings; my @array1 = ( 1, 2, 3, 4, 5); my @array2 = ( 1, 2, 3, 4, 5); list(\@array1,\@array2); sub list { foreach my $r (@_) { foreach my $c (@$r) { print $c . " "; } print "\n"; } }
    --
    if ( 1 ) { $postman->ring() for (1..2); }