Dela Lovecraft <> wrote:
> Is there a way of altering a variable sent as a reference
> to a subroutine in Perl *without* using a return value?
Yes.
In fact, you can alter a variable even if it is NOT a reference.
(as long as it IS an "lvalue".)
[snip: call-by-value vs. call-by-reference]
> Is such a thing possible in Perl?
Yes.
> Suppose I had a sub
Then you would surely read the docs for subroutines (perlsub.pod)
and come across this:
Because the assignment copies the values, this also has the effect
of turning call-by-reference into call-by-value. Otherwise a
function is free to do in-place modifications of C<@_> and change
its caller's values.
and you would have already known the answer to your question.
To get call-by-reference (the default) in Perl:
by_ref($x);
sub by_ref { $_[0] += 10 }
To get (the effect of) call-by-value in Perl:
by_val($x);
sub by_val { my $num = $_[0]; $num += 10 } # make copy, operate on copy
Neither of them use what is termed a "reference" in Perl (ie. perlref.pod).
--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas