Chinaunix

标题: 向高手请教,看这段代码问题出在哪里? [打印本页]

作者: Crystalyyin7    时间: 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


作者: Crystalyyin7    时间: 2011-06-22 16:58
怎么没得人顶啊?是我问题没有说清楚么?




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2