in reply to Table in Perl CGI
Cgi module has been deprecated removed from core, so I think it is better to learn about Template toolkit, see how to use hash on TT
Regards,#!/usr/bin/perl -w use strict; use Template; # Define hash my %fruits= ( "naranja" => "naranja" , "limón" => "amarillo" ); # Simulate a file (this content should be separated normally, on a fil +e) my $html = << 'EOT'; <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>fruits and colors</title> </head> <body> <table border="1"> <tr> <th>Fruit</th> <th>Color</th> </tr> [%# The end string "-%" will remove empty lines from source code -%] [% FOREACH fruit IN fruits.keys -%] <tr> <td> [% fruit -%] </td> <td> [% fruits.$fruit -%] </td> </tr> [% END -%] </table> </body> </html> EOT # Create the template var: my $template=Template->new(); # Process the template, telling that fruits var inside the template is + %fruits on perl code # and that $html has the template text: $template -> process (\$html,{ fruits => \%fruits }) || die $template- +>error(); # Read man Template to know more about this module
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Table in Perl CGI
by ww (Archbishop) on Aug 02, 2015 at 13:58 UTC | |
|
Re^2: Table in Perl CGI
by 1nickt (Canon) on Aug 02, 2015 at 15:19 UTC |