Tôi có đoạn code perl sau:Tại sao Perl không đánh giá được vấn đề từ Test :: Cmd :: Common-> unlink?
use strict;
use warnings;
use Test::Cmd::Common;
my $path = "/something/not/available";
my $test = Test::Cmd::Common->new(string => 'File system operations');
eval{
$test->unlink("$path");
};
ok([email protected], "file unlike");
print "done.\n";
Các $ Test-> unlink() dòng sẽ thất bại và ném ngoại lệ. nhưng vấn đề: eval không xử lý ngoại lệ đó và việc thực thi mã bị gián đoạn.
đầu ra:
$ perl test.pl
could not unlink files (/something/not/available): No such file or directory
NO RESULT for test at line 561 of /home/y/lib/perl5/site_perl/5.8/Test/Cmd/Common.pm (Test::Cmd::Common::unlink)
from line 9 of test.pl.
là eval làm công việc ngay tại đây? hoặc tôi hiểu nhầm điều gì đó?
F.
chưa được kiểm tra, nhưng làm thế nào về '* Test :: Cmd :: no_result = sub { chết 'Không có kết quả'} '? – jrockway