# This function takes a value by reference, # which is the responsiblity of the caller. sub fref { my ($var) = @_; $$var = $$var . " Python"; return $$var; } # This function defines a prototype which takes # a reference instead of a scalar. This way the # caller doesn't have to do anything special. sub fprot(\$) { my ($var) = @_; $$var = $$var . " Python"; return $$var; } # The reference version requires a backslash before any # passed parameters. my $test = "Monty"; print fref(\$test),"\n"; print $test,"\n"; # While the prototype means that you don't have to worry # about doing anything special. my $test = "Learning"; print fprot($test),"\n"; print $test,"\n";
In reply to Re: Subroutine that modifies actual variable
by tadman
in thread Subroutine that modifies actual variable
by darkomen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |