Just put a backslash in front of the dollar-sign when you pass the variable to the function.
Don't forget to de-reference the variable inside the function ...
use strict; use warnings; my $x = 10; &function( \$x ); # if I change $x = 5 print $x; # $x = 10 sub function { my $x = $_[0]; $$x = 5; } # End function subroutine
-- -- GhodmodeBlessed is he who has found his work; let him ask no other blessedness.
In reply to Re: How to pass by reference
by GhodMode
in thread How to pass by reference
by tanyeun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |