L
Larry
The following code snippet shows how I do "pass by reference" in
Perl. It works fine, but I'm wondering... is there a less verbose way
to do this?
(I know in this simple example, I could avoid the typeglob assignment
and just use $$arg instead of $arg, but in a more complex usage, that
would bug me... I'd rather just use the more normal-looking $arg
everywhere.)
-------------
sub squareMe (\$) {
my ($argRef) = @_;
local *arg = $argRef;
our $arg;
$arg *= $arg;
}
my $n = 7;
squareMe $n;
print "$n\n"; # prints 49
Perl. It works fine, but I'm wondering... is there a less verbose way
to do this?
(I know in this simple example, I could avoid the typeglob assignment
and just use $$arg instead of $arg, but in a more complex usage, that
would bug me... I'd rather just use the more normal-looking $arg
everywhere.)
-------------
sub squareMe (\$) {
my ($argRef) = @_;
local *arg = $argRef;
our $arg;
$arg *= $arg;
}
my $n = 7;
squareMe $n;
print "$n\n"; # prints 49