Hello,

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

See next code to see how to work with your example:
#!/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
Regards,
Updated after read Re^2: Table in Perl CGI
Updated with an example after read Re^2: Table in Perl CGI, i think it is better to know about TT before than after.

In reply to Re: Table in Perl CGI by i5513
in thread Table in Perl CGI by alokranjan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.