How Do I Read A Text File By Putting Its Data In A Table Using CGI In Perl? February 05, 2023 Post a Comment The CGI to read the data from merch.txt works but how can I put this in a table? HTML File: Solution 1: Using your raw embedded HTML approach, it's not hard. But it is incredibly ugly. print <<END_OF_HTML; <html> <body> <table> <tr><th>Sku</th><th>Cust</th></tr> END_OF_HTML for (@orders) { my ($sku, $cust) = split /\|/; print '<tr><td>', CGI::escapeHTML($sku), '</td>', '<td>', CGI::escapeHTML($cust), '</td></tr>'; } print <<END_OF_HTML; </table> </body> </html> END_OF_HTML Copy But mixing raw HTML with your Perl code is a terrible idea. Please use a templating engine instead. I recommend the Template Toolkit. Here's a simple CGI program using TT to do what you need.Baca JugaSteps In Order To Pass Data From Html Form To Perl ScriptHow To Use Python/cgi For File UploadingExecute A Cgi Each Time A Button Was Clicked Without Changing The Current Html Page #!/usr/bin/perl use strict; use warnings; use Template; use CGI qw[header]; my $tt = Template->new; # Best practice: three-arg open() and lexical filehandles open my $ord_fh, '<', 'merch.txt' or die $!; my @orders = <$ord_fh>; close $ord_fh; my @order_data = map { my ($sku, $cust) = split /\|/; { sku => $sku, cust => $cust } } @orders; print header; $tt->process('orders.tt', { orders => \@order_data }) or dir $tt->error; Copy And you'll need a template that looks something like this: <html> <head> <title>Orders</title> </head> <body> <h1>Orders</h1> <table> <tr><th>Sku</th><th>Cust</th></tr> [% FOREACH order IN orders -%] <tr><td>[% order.sku | html %]</td><td>[% order.cust | html %]</td></tr> [% END -%] </table> </body> </html> Copy Share You may like these postsDeleting And Updating Data From DatabaseHow Do I Read A Text File By Putting Its Data In A Table Using Cgi In Perl?Retrieve Value From A Form And Write To A FileWhy Is My Perl Replace Not Working? Post a Comment for "How Do I Read A Text File By Putting Its Data In A Table Using CGI In Perl?"