that makes a copy.my $t = shift;
There are several ways to make a variable alias to an existing value, but, shame on Perl, none are quite what I'd call "easy". For example:
which uses a global variable $t. With local you can restrict the damage, but it'll still not pass strict — you still need to declare $t – but not using "my"!*t = \($_[0]);
another way is using for in a non-obious way (for can make a loop variable that is an alias for each item it iterates over, and with a scalar it will loop exactly one):
for my $t ($_[0]) { # ... the rest of the sub body }
There is even a few Alias modules on CPAN, the most interesting one always looked to me to be Data::Alias but I must confess I've never used it. (I tried to, long time ago, but it wouldn't compile back then.) Actually, looking at it now, I think Lexical::Alias might be more interesting — if it works.
In reply to Re: global, write-able vars
by bart
in thread global, write-able vars
by zeltus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |