in reply to Referencing the locals
${a} is just another way to write $a (perldata). ${'a'} is a symbolic reference. The latter is forbidden under strict, and that's a good thing, as it can easily cause all kinds of hard-to-debug chaos (Update: one example). See also Use strict and warnings.
The typical case where I want to use it is when I have a handful of arrays and want to do stuff with each of them ... How can I reference the local ones?
No, you don't want to ;-) You likely want a hash of arrays instead (perldsc).
my %animals = ( cat => [1,2,3], dog => [5,6], pig => [4,3,2,1], );
See also Why it's stupid to `use a variable as a variable name'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Use case for symbolic references (was: Re^2: Referencing the locals)
by Bod (Parson) on Apr 28, 2021 at 21:04 UTC | |
by haukex (Archbishop) on Apr 28, 2021 at 21:24 UTC | |
by choroba (Cardinal) on Apr 28, 2021 at 21:22 UTC | |
by LanX (Saint) on Apr 29, 2021 at 02:35 UTC | |
by LanX (Saint) on Apr 29, 2021 at 02:39 UTC |