G
Gunnar Hjalmarsson
Dela said:Is there a way of altering a variable sent as a reference to a
subroutine in Perl *without* using a return value?
Suppose I had a sub doSomething which added 10 to a value. Assuming
I sent it by reference, it could like something like this:
sub doSomething
{
my $reference = shift;
my $value = $$reference;
return ($value + 10);
}
And it would be called:
my $x = 1;
my $y = doSomething(\$x);
No problem. But is there a way I could call the sub such that the
value of $x could be altered in situ without returning a value,
even over different packages? Something like:
my $x = 1;
myOtherPackage::doSomething(\$x); #such that $x now equals 11
sub doSomething { ${$_[0]} += 10 }
/ Gunnar