On 2011-06-03 17:37, sono...@fannullone.us wrote:
Maybe it's too early in the morning here, but I can't seem to remember
how to use a lexical $variable that is defined inside a foreach loop, outside
of that loop. =:\
Here's the loop:
foreach my $name (split (/, */, $names)) {
next unless ($name =~ /\w/);
my $sortstr = substr("00$totalcells", -2);
$html =~ s|</td><td|</td>\n<td|g;
$cell{"$sortstr$name"} = "<!--//CELL $name//-->";
$cell{"$sortstr$name"} =~ s/\[NAME\]/$name/sig;
$totalcells++;
}
I want to use "$name" in another loop just after this one, but when I do, I get
"Global symbol $name requires explicit package".
Could someone please point me in the right direction?
What would be the use of that?
If you declare $name before the loop, it will (after leaving the loop)
have the last value assigned to it. What would you want that for?
To me, yours is an X-Y problem. (see google)
You should probably just declare a new variable for the other loop.
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/