in reply to How to pass by reference
There's a couple of options. You can use the aliasing behavior of @_, or you can pass an actual reference.
sub func_alias { $_[0] = 5; } sub func_ref { my $ref = shift; $$ref = 5; } my $x; func_alias($x); print "x = $x\n"; my $y; func_ref(\$y); print "y = $y\n";
The latter is probably better, as it is less likely to cause surprise the caller (ie, it's more explicit that you're potentially modifying the function parameter).
bbfu
Black flowers blossom
Fearless on my breath
|
---|
In Section
Seekers of Perl Wisdom