Huh, I didn't know that, about the shallow copy. But in this case, since I'm just trying to "rename" the array, shallow copy seems like the right thing.
There are of course situations where you can't avoid repetition, but I always figured this was a neat shortcut in Perl (I can't think of any other language that would allow it). I often find that I want to, for example, open cats.txt, @cats=<$fh>, $type{$_}='cats', print "there were $cats cats", $max{'cats'}=max(@cats), or whatever the case may be – and then do the same thing for 'dogs'. I'm not aware of any other way that's as succinct and simple as looping over the strings.
There are a lot of people who argue that you should always use "strict", basically changing the language into a stricter version of itself. There are also those who argue that you should use an even more strict version of Perl, and that it's called Python. Different preferences, I guess.
In reply to Re^3: Referencing the locals
by Chuma
in thread Referencing the locals
by Chuma
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |