(e-mail address removed)-berlin.de wrote:
Larry wrote:
The following code snippet shows how I do "pass by reference" in
Perl. It works fine, but I'm wondering... is there a less
verbose way to do this?
[...]
Do you really want side effects ?
Passing by reference does this.
Guess this is too simple to make that decision.
sub squareMe($) {
my ($arg) = @_;
$arg *= $arg;
}
my $n=7;
$n = squareMe $n; # no side effects
I hate it when my variables get changed somewhere else and I have
to track it down for debugging!
That raises the question why you are using the mutator "*=" at all.
It doesn't do anything useful.
sub square_me {
my $arg = shift;
$arg*$arg;
}
would be exactly equivalent, as would be
sub square_me { $_[0]*$_[0] }
Anno
The beauty of perl "Always more than one way to skin a cat"