better way to pass by reference in Perl?
- by JoelFan
I am doing pass-by-reference like this:
sub repl {
local *line = \$_[0]; our $line;
$line = "new value";
}
sub doRepl {
my $foo = "old value";
my ($replFunc) = @_;
$replFunc->($foo);
print $foo; # prints "new value";
}
doRepl(\&repl);
Is there a cleaner way of doing it?
Prototypes don't work because I'm using a function reference (trust be that there's a good reason for using a function reference).
I also don't want to use $_[0] everywhere in repl because it's ugly.