in reply to Re: Is it possible to do pass by reference in Perl?
in thread Is it possible to do pass by reference in Perl?
Parameters are passed by value in Perl. But we have an operator, the backslash, that returns reference to any variable (scalar or composite). So the net result is that we have a mechanism to pass parameter by reference.
Admittedly, this not very clean, because the formal parameter is declared as a scalar even if it is a reference to a non scalar. I guess that was the point that tried to convey the sentence: It is only possible to pass scalars by reference to a sub.
tilly messages me: another example of how to pass arrays by reference is by using prototypes. Unlike using \ in user code, that is transparent.. So Perl has call by reference after all (even if it was quite a late addition?).sub foo { my $a = shift; push @$a, "foobar"; } my @a = (); foo \@a; # passing a value that is a reference to @a print $a[1]; # prints "foobar"
-- stefp
|
|---|