M
Mark Seger
I'd have thought this would have been answered in some of the
documentation on using references but if it was I missed it.
I understand that if I want to call a function and pass it a reference
to a scalar I can then modify that scalar within the function as follows:
sub foo {
my $ref=shift;
$$ref='new value';
}
and it works just fine. However, I want to use that scalar within the
function many times and don't want to call it $$ref every time because
it feels clumsy.
Is there some other way? I thought I could make a reference to that
reference by something like $var=\$$ref and just access $var but that
didn't work. My REAL motive for asking is I have some code that passes
parameters by value and I'd like to go back and pass them by reference
without have to change all the other code that touches them.
Then again, maybe the perlish way to do it IS to refer to them
everywhere as $$ref, $@ref or %$ref just to be clearer about what it
really going on.
-mark
documentation on using references but if it was I missed it.
I understand that if I want to call a function and pass it a reference
to a scalar I can then modify that scalar within the function as follows:
sub foo {
my $ref=shift;
$$ref='new value';
}
and it works just fine. However, I want to use that scalar within the
function many times and don't want to call it $$ref every time because
it feels clumsy.
Is there some other way? I thought I could make a reference to that
reference by something like $var=\$$ref and just access $var but that
didn't work. My REAL motive for asking is I have some code that passes
parameters by value and I'd like to go back and pass them by reference
without have to change all the other code that touches them.
Then again, maybe the perlish way to do it IS to refer to them
everywhere as $$ref, $@ref or %$ref just to be clearer about what it
really going on.
-mark