2

clearcase ビューの最終アクセス日を見つけようとしています。perl スクリプトは次のようになります。

    @Property = `cleartool lsview -prop $viewtag ` ;

foreach $property (@Property)
    {
    $last_accessed = $property if ( $property =~ /^Last accessed / ); 
            # | cut  -b 15-24 | awk -F '-' '{ print $3"/"$2"/"$1 }'
    }

私が直面している問題は、cleartool コマンドが失敗した場合に perl スクリプトが終了することです。cleartool がエラーを返しても perl を続行させたい。

BR マニ。

4

2 に答える 2

8

シンプルでプリミティブな方法は、失敗する可能性のあるコードを eval ブロッ​​ク内に配置することです。

eval { @Property = `cleartool lsview -prop $viewtag ` };

そうすれば、cleartool が失敗しても Perl スクリプトは続行されます。

正しい方法は、Try::Tinyのような適切なモジュールを使用することです。エラーは、変数 $_ の catch ブロック内で使用できます。

try {
    @Property = `cleartool lsview -prop $viewtag `;
}
catch {
    warn "cleartool command failed with $_";
};
于 2013-01-22T11:49:03.630 に答える
3

" What is the best way to handle exceptions in perl? "で推奨されているように、 " Try::Tiny " を試すことができます。

もう 1 つの方法はeval、cleartool コマンドを使用することです。

eval { @Property = `cleartool lsview -prop $viewtag` };
if ($@) {
    warn "Oh no! [$@]\n";
}
于 2013-01-22T11:47:34.257 に答える