我目前在我的Perl腳本的一部分代碼(工作正常):避免使用警告的try-catch時使用try ::微型和模塊::運行
try {
no strict 'refs';
require_module $modules{$action_name};
if (&{"FFTG::${actiontype}::run"}($action, $fs, $log)) {
$log->res("SUCCESS");
} else {
if ($action->{mandatory}[0] == 1) {
$log->res("FAIL, exiting.");
last ACTION;
} else {
$log->res("FAIL, but not mandatory, continuing..");
}
}
}
catch {
$log->res("MODULE NOT FOUND");
print "no module found for action '$actiontype', unable to process this action\n";
#warn $_;
};
,但不幸的是,該腳本的輸出顯示在輸出的中間這3個錯誤(所有行開頭退出子程序):
starting transfer ..
no module found for action 'Transfer', unable to process this action
no module found for action 'Transfer', unable to process this action
no module found for action 'Archive', unable to process this action
Exiting subroutine via last at ./bin/fftgv2.pl line 130.
Exiting eval via last at ./bin/fftgv2.pl line 130.
Exiting subroutine via last at ./bin/fftgv2.pl line 130.
ending transfer
即使腳本完美的作品,我覺得很「髒」到上顯示這些錯誤標準輸出。
有沒有辦法擺脫它們? (我不能使用如果/然後等..因爲我不希望腳本退出與此require_module事情)。 我只是希望我的腳本來顯示一個警告,如果它不能找到一個模塊(它),而不是這些警告
再次感謝 問候
你確定他們不是來自你寫的代碼,或者是你自己的代碼庫嗎? – simbabque
https://grep.metacpan.org/search?size=20&q=via+last&qd=&qft= – simbabque
我認爲他們是來自某事。但我還沒有完全理解這一點。 – simbabque