tomazos has asked for the wisdom of the Perl Monks concerning the following question:
I want to pass a my variable to a subrountine that then does something to it.
sub alter_var(???) { my $var_in_sub = ???; # alter $var_in_sub, eg $var_in_sub =~ s/a/b/g; } my $var_elsewhere = 'aaa'; alter_var($var_elsewhere); print $var_elsewhere; # should print 'bbb'
Any ideas as to what goes in the ??? bits? Essentially I want to make $var_in_sub an alias for $_[0].
Update: In the actual application the scalar is quite big, so I'd like to pass it by reference without copying the data.
I'd also like to use a meaningful name rather than $_[0] throughout the subroutine.
I'd also like to not have to reference (\$) and dereference ($$) all over the place.
I just want too much. :)
Lexical::Alias is what I want but I'm running 5.6.1, looks like 5.8.1+ is needed from the docs.
All bow to BrowserUK. Truly cool.
-Andrew.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Simple Pass By Reference
by BrowserUk (Patriarch) on Jul 26, 2005 at 01:56 UTC | |
by cosimo (Hermit) on Jul 26, 2005 at 16:01 UTC | |
by tomazos (Deacon) on Jul 26, 2005 at 17:27 UTC | |
|
Re: Simple Pass By Reference
by esskar (Deacon) on Jul 25, 2005 at 23:54 UTC | |
by tomazos (Deacon) on Jul 26, 2005 at 00:00 UTC | |
by friedo (Prior) on Jul 26, 2005 at 00:12 UTC | |
by tomazos (Deacon) on Jul 26, 2005 at 00:27 UTC | |
by sk (Curate) on Jul 26, 2005 at 00:57 UTC | |
by PodMaster (Abbot) on Jul 26, 2005 at 00:52 UTC | |
| |
|
Re: Simple Pass By Reference
by tlm (Prior) on Jul 26, 2005 at 04:02 UTC | |
by BrowserUk (Patriarch) on Jul 26, 2005 at 04:49 UTC |