- 论坛徽章:
- 0
|
帮忙帮到底嘛
#!/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);
my $tmpl_file = 'log.tmpl'; # Change it
my $template = HTML::Template->new(filename => $tmpl_file);
my $q = CGI->new;
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;
my @log;
for (@data) {
my %t;
@t{qw/date computer platform command result/} = (split);
push @log, \%t if $t{date} =~ /$selected/;
}
$template->param(selected => $selected,
log => \@log,
dates => \@dates);
print $q->header, $template->output;
————————————————————————
<!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>
<script>
function dosubmit( dateobj ) {
dateobj.form.submit();
}
</script>
</HEAD>
<BODY>
<form>
<select name="rundate" onChange="dosubmit(this);">
<option value=<tmpl_var name="selected"> selected><tmpl_var name="selected"></option>
<tmpl_loop name="dates">
<option value=<tmpl_var name="date"> ><tmpl_var name="date"></option>
</tmpl_loop>
</select>
</form>
<table border="1">
<tr><th>日期</th><th>计算机名</th><th>系统平台</th><th>运行命令</th><th>运行结果</th><tr>
<tmpl_loop name="log">
<tr>
<td><tmpl_var name=date></td><td><tmpl_var name=computer></td><td><tmpl_var name=platform></td><td><tmpl_var name=command></td><td><tmpl_var name=result></td>
</tr>
</tmpl_loop>
</table>
</BODY>
</HTML> |
|