如何使用perl cgi为我的perl输出创建表? [英] How to create table for my perl output using perl cgi?

查看:105
本文介绍了如何使用perl cgi为我的perl输出创建表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码和输出,我无法使用perl为每行创建不同的行?

Here is my code and output i was unable to create the different row for my each line using perl?

这是我的代码:

   use strict;
    use warnings;
    use CGI;
    open(my $file1,"as.txt");
    my $firstline=<$file1>;
    $firstline=~s/.*=//g;
    my @words=split /,/,$firstline;
    my $finalline=join("\n",@words);
    close $file1;
    print "Content-type:text/html\n\n"
    print<<"EOF";
    <html><body>
    <table style="width:100%">
    <tr>
    <th>UserName</th>
    <th>Access</th>
    </tr>
    <tr>
    <td>$finalline</td>
    <td>
    <input type="checkbox" value="check2" mulitple checked>Read
    <input type="checkbox" value="check2" mulitple>Write
    <input type="checkbox" value="check2" mulitple>Owner
    </td>
    </tr>
    </table></body></html>
    EOF



我的PERL输出(即$ finalline)
sankar
morien3

MY OUTPUT FOR PERL (I.E $finalline) sankar morien3

我以表格格式将以下表格作为输出:

i got the following table as my output in table format:

UserName    Access
sankar morien3 Read Write Owner

预期输出:

UserName    Access
sankar  Read Write Owner
morien3 Read Write Owner

输入文件:(即as.txt)

Input file:(i.e as.txt)

cskTeam = sankar, mobrien3
[csk:/]

* = r
@cskTeam = rw


推荐答案

您必须了解HTML布局的工作方式。

You must know about how HTML layout will work.

即使您的代码也无法在终端上提供预期的结果。

Even your code won't give your expected result in terminal.

用html \n 没有意义,< br> 用于html中的换行。但这逻辑也不会在您的代码中起作用。

In html \n not make sense, <br> it is for new line in html. But this logic also won't work in your code.

您正在使用 \n 加入数组,然后打印数据,它将逐行执行注释。

You are joining the array with \n, then printing the data it will execute the comment line by line what you have mentioned.

首先,您已打印 $ finalline 变量,因此结果为

First you have printing the $finalline variable so it result is

sankar \n morien3  

\n不会在html中考虑。按照< td>

\n will not consider in html. Storing in one cell as per <td>

存储在一个单元格中,然后创建

最后,您的代码应如下所示。

Finally your code should be as follows.

#!/usr/bin/perl
use warnings;
use strict;
use CGI;

use CGI::Carp qw(fatalsToBrowser);

print "Content-Type: text/html \n\n";


open my $file1,"<","as.txt";
my $firstline=<$file1>;
$firstline=~s/.*=//g;
my @words=split /,/,$firstline;
close $file1;


print<<"EOF";
<html><body>
<table style="width:50%; ">
<tr>
<th style="text-align:left">UserName</th>
<th style="text-align:left">Access</th>
</tr>
EOF
foreach (@words)
{
print <<EOF;
<tr>
<td>$_</td>
<td>
<input type="checkbox" value="check2" mulitple checked>Read
<input type="checkbox" value="check2" mulitple>Write
<input type="checkbox" value="check2" mulitple>Owner
</td>
</tr>
EOF
}
print <<EOF;
</table></body></html>
EOF

这篇关于如何使用perl cgi为我的perl输出创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆