use Win32::olE;eval { local $SIG{ALRM} = sub { dIE "alarm\n" }; alarm 10; # schedule alarm in 10 seconds &do_the_subroutine; alarm 0; # cancel the alarm};if ($@) { $error_string .= $script; #Do something else if the subroutine took too long.}do_the_subroutine{# use existing instance if Excel is already running eval {$ex = Win32::olE->GetActiveObject('Excel.Application')}; dIE "Excel not installed" if $@; unless (defined $ex) { $ex = Win32::olE->new('Excel.Application',sub {$_[0]->Quit;}) or dIE "Oops,cannot start Excel"; } # get a new workbook $book = $ex->Workbooks->Add; # write to a particular cell $sheet = $book->Worksheets(1); $sheet->Cells(1,1)->{Value} = "foo"; # write a 2 rows by 3 columns range $sheet->Range("A8:C9")->{Value} = [[ undef,'Xyzzy','Plugh' ],[ 42,'Perl',3.1415 ]]; # print "XyzzyPerl" $array = $sheet->Range("A8:C9")->{Value}; for (@$array) { for (@$_) { print defined($_) ? "$_|" : "<undef>|"; } print "\n"; } # save and exit $book->SaveAs( 'test.xls' ); undef $book; undef $ex;}
& do_the_subroutine永远不会返回,所以我无法继续前进.我也无法将这段代码放在该子程序中.有什么想法吗?
解决方法@H_502_17@ 我怀疑你想要做的事情本身就不可能在windows上发出警报.来自perldoc perlport:
总结alarm Emulated using timers that must be explicitly polled whenever Perl wants to dispatch “safe signals” and therefore cannot interrupt blocking system calls. (Win32)
以上是内存溢出为你收集整理的Perl子例程超时全部内容,希望文章能够帮你解决Perl子例程超时所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)