or you could leave out the "$key".

foreach (keys %pages) {
        print "<a href=\"$pages{$_}\">$key</a>\n";
}


On Sun, 2002-06-23 at 08:59, Marty Landman wrote:
> At 07:37 AM 6/23/02 -0400, Kyle Babich wrote:
> 
> >foreach $key(keys %pages) {
> >         print "<a href=\"$pages{$key}\">$key</a>\n";
> >}
> >
> >It says I need it for $key but no matter where I put the my it won't
> >stop giving me that error.  Where in that does the my go?
> 
> Kyle, this is a syntactic 'not-nicety' of Perl imho. You need a separate 
> line like so:
> 
> my $key;
> 
> This must of course go before the loop, preferably right before it as this 
> is good style. Hope I don't get flamed to death now. :)
> 
> BTW, an alternative that I sometimes use in the case where I need a bunch 
> of scalars in a sub is to just declare a hash, e.g.
> 
> my %vars;
> 
> Now I can use $vars{moe}, $vars{curly} etc... to my heart's content with 
> only the one 'my' variable.
> 
> hth,
> Marty
> 
> --
> SIMPL WebSite Creation: http://face2interface.com/Home/Demo.shtml
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to