The example below shows what works, as well as how it *doesn't* work when placed inside a CGI.pm HTML table. I've read TPJ's Coping with Scoping plus perldoc CGI.pm, but am just not getting it.
Direction or sample code greatly appreciated.
cheers,
ybiC
#!/usr/bin/perl -wT use strict; use CGI::Carp qw (fatalsToBrowser); use CGI::Pretty qw(:all); my %urlhash = ('Perl Monks' => "http://www.perlmonks.org/", 'Debian' => "http://www.debian.org/", 'OpenBSD' => "http://openbsd.org/", ); print header(-type => 'text/html', -expires => 'now'), start_html (-title => 'hash.cgi'); # FOREACH & WHILE SYNTAX WORKS FINE HERE #print "<p> ==HASH FOREACH=="; #foreach my $key (keys %urlhash) { # print "<br>", a({href => "$urlhash{$key}"}, "$key"), # } #print "<p> ==HASH WHILE=="; #while((my $key, my $value) = each(%urlhash)) { # print "<br>", a({href => "$urlhash{$key}"}, "$key"), # } print table, (Tr, (td, ( # BUT NEITHER WORKS FROM INSIDE CGI.PM TABLE. # 'syntax error at line 29, near "foreach"' foreach $main::key (keys %urlhash) { print "<br>", a({href => "$urlhash{$key}"}, "$key"), } # 'syntax error at line 34, near "while"' while(($main::key, $main::value) = each(%urlhash)) { print "<br>", a({href => "$urlhash{$key}"}, "$key"), } ), ), ); # close td, Tr, table print end_html;
In reply to while, foreach inside CGI.pm table by ybiC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |