简体   繁体   English

在我的HTML表中获取多余的额外列

[英]Getting an unwanted extra column in my HTML table

Ok, I'm trying to make an HTML table to display some results from the finger command on my system, but I'm getting a leading column of blank space that I can't figure out how to remove. 好的,我试图制作一个HTML表来显示我的系统上的finger命令的一些结果,但是我得到的空格是前导,我不知道如何删除。 Here is the code I'm using. 这是我正在使用的代码。

#!/usr/bin/perl;
use Modern::Perl;
use CGI::Carp qw/fatalsToBrowser/;
use CGI qw/:standard *table *Tr/;

my @fingeroutput = `finger`;
my @info;
my @td;

foreach my $finger (@fingeroutput){
    $finger =~ /(\w+)\s+(\w*\s\w*)\s+(\w+\/\d+)\s+(\d*d*:*\d*)\s+(\w+\s\d+\s\d+:\d+)\s(.+)/;
        push (@info, ("$1", "$2", "$4", "$6") );
}

while (my @data = splice @info, 0, 4 ) {
    push @td, td( \@data );
}

print header(), start_html(-title=>'Basic Stuff');

print start_table({-border=>2, width=>"50%"});

print th([ 'Login', 'Name', 'Idle', 'Host']);
foreach my $row ( @td ) {
    print start_Tr;
    print td ( $row );
    print end_Tr;
}

print end_table;

print end_html();

The first problem I'm having is when the table prints out, the first row is always a row of blank space. 我遇到的第一个问题是表格打印出来时,第一行始终是空白行。

My second problem is that the Login column is coming up all blank space and all the data is shifted a cell to the right leaving my host section in a column with no header. 我的第二个问题是,“登录”列即将出现所有空白,并且所有数据都向右移动一个单元格,从而使“主机”部分保留在没有标题的列中。

This is my first time working with CGI and HTML tables, so I've done a lot of research to get to this point. 这是我第一次使用CGI和HTML表,因此我做了很多研究以达到这一点。 The only thing left is getting the table format right. 剩下的唯一事情就是使表格格式正确。 What am I doing wrong? 我究竟做错了什么?

The second problem turned out to be in this code: 第二个问题竟然是这段代码:

while (my @data = splice @info, 0, 4 ) {
    push @td, td( \@data );
}

By changing it to: 通过将其更改为:

while (my @data = splice @info, 0, 4 ) {
    push @td, ( \@data );
}

I got rid of the extra leading column. 我摆脱了多余的领先专栏。 I still haven't figured out why I'm getting a blank row to begin my table. 我仍然没有弄清楚为什么我要得到一个空白行来开始我的表。

I did the quick fix of adding in a 我做了快速修复,添加了

shift @td;

If anyone can see why I was getting that blank row in the first place that would be helpful. 如果有人可以看到为什么我会首先获得该空白行,那将很有帮助。 Was it because I was using a push from the start to get my data in to the array? 是因为我从一开始就使用推送将数据导入到阵列中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM