免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2299 | 回复: 1
打印 上一主题 下一主题

向高手请教,看这段代码问题出在哪里? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-21 18:08 |只看该作者 |倒序浏览
我写了段代码,但是有的时候会有问题:excel明明已经关掉了,但是任务管理器中显示excel进程还在运行。请教高手帮忙看下,这个代码是不是有bug。


#!/usr/bin/perl -w

use warnings;
use diagnostics;
use Text::CSV_XS;
use Spreadsheet:arseExcel;
use Spreadsheet:arseExcel::FmtUnicode;


$filename="Test.xls";
my $oExcel = new Spreadsheet:arseExcel;
my $code = "gb2312";
my $oFmtJ = Spreadsheet:arseExcel::FmtUnicode->new(Unicode_Map =>$code);
my $oBook = $oExcel->arse( $filename, $oFmtJ );

my $sheet=$oBook->{Worksheet}[0];
my $sheet_name=$sheet->{Name};
#print $sheet_name;


my $row=1;
my $result="";
my $key="";
my %table=();
my $item;
open Lot_loss, ">>Lot_loss.txt" or die "Cannot write to: $!";
open Key_record, ">>Key_record.txt" or die "Cannot write to: $!";
print Lot_loss "This mail will be sent by user.\n";
print Lot_loss "Action\tTester  \tPROD \tLast Fail\tRepeated Fails\t\t\t\t\tTrend\n";

my $file="Key_record.txt";
open(MYFILE,$file) || die "Can not open the file: $!";

my $count =0;
my @temp;
my @time;
while ($item=<MYFILE>
{
  @temp = split(/\n/, $item);
  $item = $temp[0];
  $table{$item}=$count;
  $count = $count+1;
}



while($row<50)
{
        my $col=33;
        my $record=0;
        my $cell=$sheet->get_cell($row,$col);
        my $Flag=$cell->value;
        if ($Flag==1)
        {
          $record=$record+1;
        }
        $col=$col-1;
        $cell=$sheet->get_cell($row,$col);
        $Flag=$cell->value;
        if ($Flag==1)
        {
          $record=$record+2;
        }
        $col=$col-1;
        $cell=$sheet->get_cell($row,$col);
        $Flag=$cell->value;
        if ($Flag==1)
        {
          $record=$record+4;
        }        
        my $Rcol=0;
        if ($record==1 || $record==5)
        {
          #Action
          $result="      \t";
          #tester
          my $cell=$sheet->get_cell($row,$Rcol);
          my $line=$cell->value;
          $result=$result.$line."\t";
          $key=$line;
          $Rcol=8;
          $cell=$sheet->get_cell($row,$Rcol);
          $line=$cell->value;
          @time = split(/\./, $line);
          $line = $time[0];
          $key=$key.$line;
          #prod
          $Rcol=9;
          $cell=$sheet->get_cell($row,$Rcol);
          $line=$cell->value;
          $result=$result.$line."\t";
          $key=$key.$line;
          #Last Fail
          $Rcol=22;
          $cell=$sheet->get_cell($row,$Rcol);
          $line=$cell->value;
          $key=$key.$line;
          $len=rindex $line."\$", "\$";
          #print "$len\n";
          if ($len==6)
          {
            $line=$line."   ";
          }
          if ($len==
          {
            $line=$line." ";
          }
          $result=$result.$line."\t";
          #Repeated Fail
          $Rcol=23;
          $cell=$sheet->get_cell($row,$Rcol);
          if ($cell)
          {
            $line=$cell->value;
            $key=$key.$line;
            $len=rindex $line."\$", "\$";
            while ($len<41)
            {
              $line=$line." ";
              $len=$len+1;
            }
          }
          else
          {
            $line="              \t\t\t\t";
          }
          $result=$result.$line."\t";
          #Trend
          $Rcol=10;
          while($Rcol<20)
          {
            $cell=$sheet->get_cell($row,$Rcol);
            $line=$cell->value;
            $key=$key.$line;
            $result=$result.$line;
            $Rcol=$Rcol+1;
          }
          $result=$result."\n\n";
          #print $key;
            
          if(!exists($table{$key}))
          {
           $key=$key."\n";
           print Key_record $key;
           print Lot_loss $result;
           #print "False";
          }
          else
          {
            #print "True";
          }
          
        }
        $row=$row+1;
}
print Lot_loss "\nAction Option:\n";
print Lot_loss "1...\n";
print Lot_loss "2...\n";
print Lot_loss "3...\n";
print Lot_loss "4...\n";


close Lot_loss;
close Key_record;

qx(del lot_loss.txt);

test.zip

1.16 KB, 下载次数: 21

论坛徽章:
0
2 [报告]
发表于 2011-06-22 16:58 |只看该作者
怎么没得人顶啊?是我问题没有说清楚么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP