免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: huanghaojie
打印 上一主题 下一主题

cgi perl里如何改变某些字条符的颜色呀 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-12-31 17:05 |显示全部楼层
原帖由 cobrawgl 于 2008-12-31 16:48 发表


没仔细看


这个就是你写的呀

代码 vi cgi-pl

#!/usr/bin/perl


use strict;
use warnings;

use CGI qw/:standard/;
use HTML::Template;

use IO::File;

my $tmpl_file = '/var/www/cgi-bin/tmplate';  # Change it
my $data_file = '/var/www/cgi-bin/log/testlog';  # Change it

my $template = HTML::Template->new(filename => $tmpl_file);
my $file = IO::File->new($data_file);

my @log;
while ($_ = $file->getline) {
        my %t;
        @t{qw/date computer platform command result Detail/} = (split);
        push @log, \%t
}
$template->param(log => \@log);

print header, $template->output;
~


vi  tmple


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=gbk">
  <TITLE> Log </TITLE>
</HEAD>
    <table align=center>
          <td><b>Hatteras CLI Automation Test Results</b> </td>
    </table>
<BODY>
  <table border="1" width="900" align=center bordercolor="#6595d6">
    <tr>
      <th align=center id=tabletitlelink height=25 width="20%" style="font-weight:normal"><b>Test Date</b></th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>System Type</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>HostName</th>
      <th align=center id=tabletitlelink height=25 width="30%" style="font-weight:normal"><b>System Command</th>
      <th align=center id=tabletitlelink height=25 width="10%" style="font-weight:normal"><b>Results</th>
      <th align=center id=tabletitlelink height=25 width="15%" style="font-weight:normal"><b>Hatteras Version</th>
    <tr>
  <tmpl_loop name="log">
        <tr>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=date></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=computer></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=platform></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=command></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=result></td>
                <td align=center id=tabletitlelink height=25 style="font-weight:normal"><tmpl_var name=Detail></td>
        </tr>
  </tmpl_loop>
  </table>
</BODY>
</HTML>

论坛徽章:
0
12 [报告]
发表于 2008-12-31 18:22 |显示全部楼层
原帖由 ynchnluiti 于 2008-12-31 17:59 发表

我的cgi环境没搭好,没法测试。所以给据选择的时间显示列表的代码没写。


非常感谢,呵呵, 这段放在哪里?

论坛徽章:
0
13 [报告]
发表于 2008-12-31 21:02 |显示全部楼层
原帖由 cobrawgl 于 2008-12-31 18:29 发表
帮忙帮到底嘛

#!/usr/bin/perl

use strict;
use warnings;

use CGI;
use HTML::Template;

use IO::File;

my $data_file = 'Your_file';  # Change it
my $file = IO::File->new($data_file) ...


哪错了,怎么web里什么也出不来,没改之前还能出来,
我把该改的两个地方的路径都改了呀,没问题,怎么就出来 呢

[ 本帖最后由 huanghaojie 于 2008-12-31 21:03 编辑 ]

论坛徽章:
0
14 [报告]
发表于 2009-01-01 01:52 |显示全部楼层
感谢cobrawgl  和 ynchnluiti  两位达人,呵呵, 我的搞定了, 晚上注意力不集中,老搞错,祝你俩2009快乐。!!!!
下面的小问题再慢慢搞定。

论坛徽章:
0
15 [报告]
发表于 2009-01-04 15:06 |显示全部楼层
新年新问题!

my @data = $file->getlines;

my %dates = ();
for (@data) {
        $dates{(split /:/, (split)[0])[0]} = 1;
}

my @dates = sort keys %dates;
my $selected = $q->param('rundate') || shift @dates;
@dates = map { {date => $_} } @dates;

这些东东好难懂
$dates{(split /:/, (split)[0])[0]} = 1;  是意思呀,  我在试着把默认的页面改成最后一次运行的日期。而不是第一次运行的日期。

[ 本帖最后由 huanghaojie 于 2009-1-4 15:07 编辑 ]

论坛徽章:
0
16 [报告]
发表于 2009-01-04 21:34 |显示全部楼层
看来真的还是解铃还需要系铃人呀。

多谢两位的出手相助。

论坛徽章:
0
17 [报告]
发表于 2009-01-04 21:41 |显示全部楼层
原帖由 cobrawgl 于 2009-1-4 19:08 发表




my $selected = $q->param('rundate') || shift @dates;

改为

my $selected = $q->param('rundate') || pop @dates;


小声问一句,那个tmplate文件是不是通过什么东东自动生成的呀?

论坛徽章:
0
18 [报告]
发表于 2009-01-05 15:40 |显示全部楼层
人性是贪婪的,呵呵, :) :) :) :) :) :) :)
现在我想实现可以按表格的每一列来分隔页面,之前是可以实现按日期来分隔页面。努力并缓慢的进行中。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP