The stupid question is the question not asked | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
@_ contaisn aliases to the parameters you pass, so if you work directly on $_[0], yo ucan change its value. It's the
that makes a copy. 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"! 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):
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
|
|