At 8:37 AM -0700 6/3/11, 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".

Declare the variable just before the loop, and remove the 'my' from the foreach statement:

my $name;
foreach $name ( ... ) {
  ...
}


--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to