|
我在做毕业设计,得到了一个perl程序,代码如下:- #!/usr/bin/perl
- print "Content-type: text/html \n\n";
- open(MyFile, "/var/log/trafic.log") || die ("Can't open file");
- open(IPMAP, "/etc/ipmap") || die ("Can't open file");
- %ipmap = {};
- while(<IPMAP>){
- chomp($_);
- ($ip, $member) = split(/\s+/, $_);
- $ipmap{$ip} = $member;
- }
- print qq(<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">);
- $i = -1;
- $tll_m = 0;
- $tll_k = 0;
- while(<MyFile>)
- {
- chomp($_);
- $i++;
- if($i == 0 || $i == 1)
- {
- print "<tr>";
- print $_;
- print "</tr>";
- next;
- }
-
- print "<tr>";
- #@colums
- ($ip, $f_i_k, $f_i_m, $c_i_k, $c_i_m, $f_o_k, $f_o_m, $c_o_k, $c_o_m)
- = split(/\s+/, $_);
-
- print qq(<td>);
- if($ipmap{$ip} ne ""){
- print "$ip($ipmap{$ip}) ";
- } else {
- print "$ip ";
- }
- print "</td>";
- print qq(<td>);
- print "$f_i_m ";
- print "</td>";
- print qq(<td>);
- print "$f_i_k ";
- print "</td>";
- print qq(<td>);
- print "$c_i_m ";
- print "</td>";
- print qq(<td>);
- print "$c_i_k ";
- print "</td>";
-
- print qq(<td>);
- print "$f_o_m ";
- print "</td>";
- print qq(<td>);
- print "$f_o_k ";
- print "</td>";
- print qq(<td>);
- print "$c_o_m ";
- print "</td>";
- print qq(<td>);
- print "$c_o_k ";
- print "</td>";
- if($i == 2){
- print qq(<td>);
- print "收费流量(M) ";
- print "</td>";
-
- print qq(<td>);
- print "收费流量(K) ";
- print "</td>";
- } else {
- print qq(<td>);
- $mil = $c_i_m + $c_o_m + int(($c_i_k + $c_o_k) / 1024);
- $kil = int($c_i_k + $c_o_k) % 1024;
- print $mil . " ";
- print "</td>";
-
- print qq(<td>);
- print $kil . " ";
- print "</td>";
- $tll_m += $mil;
- $tll_k += $kil;
- }
- #foreach (@colums){
- # print qq(<td>);
- # if($ipmap{$_} ne ""){
- # print "$_($ipmap{$_}) ";
- # } else {
- # print "$_ ";
- # }
- # print "</td>";
- #}
- print "</tr>\n";
- }
- print "<tr>";
- print "<td>";
- print "<b>总收费流量:</b>";
- print "</td>";
- print "<td><b>";
- print $tll_m + int($tll_k / 1024) . "(M)</b>";
- print "</td>";
- print "</tr>\n";
- print "</table>";
- close(IPMAP);
- close(MyFile);
复制代码
可是我在用web服务器进行查看的时候发现网页是空白的,什么都没有显示,按理来说应该将traffic.log文件中的数据以表格形式输出才对,因为我也是刚开始接触perl,对这方面的东西也不是很懂,不果程序是没有问题的,请教一下各位高手,给点意见啦~~~
拜谢~! |
|