By the way, in "Perl Best Practices" Damian Conway advises that you should always write 'my' before your for-loop variable because if you don't :
[The resulting] behaviour is contrary to all reasonable expectation. Everywhere else in Perl, when you declare a lexical variable, it's visible throughout the remainder of its scope, unless another explicit my declaration hides it. So it's natural to expect that the [variable] used in the for loop is the same lexical [variable] that was declared before the loop. But it isn't.
My code makes it neccessary to loop through an array and to output all elements using a reference.
That doesn't seem to make a lot of sense:
use strict; use warnings; use 5.010; my @arr = (10, 20, 30); for my $num (@arr) { say ${\$num}; } --output:-- 10 20 30
In reply to Re: Dereference string in foreach
by 7stud
in thread Dereference string in foreach
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |