Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML表格格式问题_Html_Perl_Html Table_Two Columns - Fatal编程技术网

HTML表格格式问题

HTML表格格式问题,html,perl,html-table,two-columns,Html,Perl,Html Table,Two Columns,我正在尝试以表格格式对齐两个数组的内容并发送电子邮件。但是表中的第二列没有按需要对齐。第二列的内容显示为一行 我还附加了输出表: #!/usr/bin/perl use strict; use warnings; use MIME::Lite; use HTML::Entities; my $msg; my @Sucess = qw(s1 s2 s3 s4 s5 s6); my @Failed = qw(f1 f2 f3 f4); my $html = '<table style=

我正在尝试以表格格式对齐两个数组的内容并发送电子邮件。但是表中的第二列没有按需要对齐。第二列的内容显示为一行

我还附加了输出表:

#!/usr/bin/perl

use strict;
use warnings;

use MIME::Lite;
use HTML::Entities;

my $msg;
my @Sucess = qw(s1 s2 s3 s4 s5 s6);
my @Failed = qw(f1 f2 f3 f4);

my $html = '<table style="width:600px;margin:0 100px" border="1" BORDERCOLOR="#000000">
    <thead><th bgcolor="#9fc0fb">Successful</th><th bgcolor="#9fc0fb">Failed</th></thead>
    <tbody>';    

$html .= "<tr><td>$_</td>" for @Sucess;
$html .= "<td>$_</td>" for @Failed;
$html .= " </tr>";


$msg = MIME::Lite->new(
    from    => 'foo@abc.com',
    To      => 'foo@abc.com',
    Subject => 'Status of Update',
    Type    => 'multipart/related'
);

$msg->attach(
    Type => 'text/html',
    Data => qq{
        <body>
        <html>$html</html>
        </body>
    },
);

MIME::Lite->send ('smtp','xyz.global.abc.com' );
$msg->send;
#/usr/bin/perl
严格使用;
使用警告;
使用MIME::Lite;
使用HTML::实体;
我的$msg;
my@Sucess=qw(s1 s2 s3 s4 s6);
my@Failed=qw(f1 f2 f3 f4);
我的$html
成功失败
';    
$html.=“$”表示@suces;
$html.=“$”表示@失败;
$html.=”;
$msg=MIME::Lite->new(
from=>'foo@abc.com',
To=>'foo@abc.com',
主题=>“更新状态”,
类型=>“多部分/相关”
);
$msg->attach(
类型=>'text/html',
数据=>qq{
$html
},
);
MIME::Lite->send('smtp','xyz.global.abc.com');
$msg->send;

首先在
@suces
中循环每个项目,对于每个项目,您:

  • 创建新行
  • 在该行中创建一个单元格
最后,显式关闭创建的最后一个表行:


您需要将构建表的代码替换为按逻辑顺序工作的代码。HTML表需要逐行定义。你不可能处理所有的成功,然后是所有的失败

我将用如下内容替换代码的中间部分:

use List::Util qw[max];

my $max = max($#Sucess, $#Failed);

for (0 .. $max) {
  $html .= '<tr><td>';
  $html .= $Sucess[$_] // '';
  $html .= '</td><td>';
  $html .= $Failed[$_] // '';
  $html .= "</td></tr>\n";
}
使用列表::Util qw[max];
我的$max=max($#成功,$#失败);
用于(0..$max){
$html.='';
$html.=$suces[$\u]/'';
$html.='';
$html.=$Failed[$\u]/'';
$html.=“\n”;
}

但实际上,我决不会将原始HTML放入Perl程序中。改用a。

soooo。。。你不相信收尾标签吗
:PYou可以自由使用Perl中有效的标识符,但是熟悉该语言的人和不熟悉英语的人会感谢您对局部变量使用
snake\u case
。首字母大写是一个特殊的问题,因为语言本身保留了全局标识符(如包名)的名称。看起来您不需要在
@success
@Failed
上使用
@success
@Failed
模板工具包的问题是,人们看到他们的依赖项和标识符(主要是
字符串)分布在多个文件中,它需要一个非常好的IDE来跟踪它们。虽然很可能将模板放入程序的
数据
部分,但这种方法在模块中有点奇怪,而且每个源文件只提供一个模板。使用类似的方法可以笨拙地克服这一问题,但任何较少的措施都会让我们难以处理多个全局标识符这听起来不像是模板工具包的问题,它听起来像是任何模板引擎的问题。而且,老实说,在使用模板的写作系统长达15年之久的时间里,我从来没有听说过你的抱怨。将显示逻辑分离到不同的文件(或多个文件)通常被视为此方法的优势。它允许具有不同技能的人员(前端开发人员与后端开发人员)都独立处理系统中自己的部分。
$html .= "<td>$_</td>" for @Failed;
$html .= " </tr>";
my @Sucess= qw(s1 s2 s3 s4 s5 s6);
my @Failed= qw(f1 f2 f3 f4);

my $html = "<table>\n";

do {
    my $s = shift @Sucess;
    my $f = shift @Failed;
    $html .= sprintf("<tr> <td> %s </td> <td> %s </td> </tr> \n", map { $_ // '' } $s, $f);
} while ( @Sucess or @Failed );

$html .= "</table>";

print $html;
use List::Util qw[max];

my $max = max($#Sucess, $#Failed);

for (0 .. $max) {
  $html .= '<tr><td>';
  $html .= $Sucess[$_] // '';
  $html .= '</td><td>';
  $html .= $Failed[$_] // '';
  $html .= "</td></tr>\n";
}