文本文件中的项目用管道符号“|”分隔。下面的CGI文件将在指定标签下的表格中显示这些项目。请看这Table Output,这就是我所拥有的。我该如何解决这些问题,因为这些项目是在他们指定的专栏中,而不仅仅是一个?有没有MySQL或SQL来保存数据,只是一个文本文件PERL CGI:如何修正拆分功能,读取/显示表格上的数据?
#!/usr/bin/perl -w
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;
print "Content-type: text/html\n\n";
print "<TABLE BORDER>\n";
print "<TR><TH>SKU Code<TH>Name<TH>Description<TH>Price";
open (ORDERS, "inventory.txt") or die "Error opening file, $!";
while(<ORDERS>) {
print "<TR>\n";
print "<TD>";
my @fields=split(/\<\*\>/);
print join(`<TD>`,@fields);
print "</TR>";
}
close ORDERS;
print "</TABLE>";
下面是一个用来存储项目的文本文件中的CGI文件
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
my $sku = param('sku_code');
my $cust = param('customer');
my $description = param('description');
my $selling = param('price');
my $price = sprintf("\$%.2f");
print <<HERE;
<HTML>
<BODY>
<H3>Here is your order...please check</H3>
SKU: $sku<br>
Name: $cust<br>
Description: $description<br>
Selling Price: $price<br>
HERE
open (ORDERS, ">>inventory.txt") or die "File error, $!";
print ORDERS "$sku|$cust|$description|$price\n";
close ORDERS;
谢谢。这非常有帮助 –