in reply to Passing argument by reference (for a scalar)
"Passing by reference" ( reference in computer science lingo) is the default in Perl since $_[0] is an alias . (NB: "alias" != "reference" in Perl)
For instance you can do
my $string = "This is a string"; printWthStrRef($string); # passing string by alias sub printWthStrRef { my $ref = \( $_[0] ); print $$ref; # prints the string print $_[0]; # prints the string $_[0] = "new"; # overwrite original $string }
You only need explicit references when passing multiple complex variables like arrays or hashes, to avoid flattening to lists.
(And even here you could use prototypes, but this is too far fetched here)
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
( disclaimer: I wrote this hours ago but the website was unresponsive for me)
|
|---|