Perl 中的 cluck 函式


Perl 中的 cluck 函式是一種超級強化型的 carp,它遵循相同的基本原則,但還打印出所有導致呼叫該函式的模組的堆疊跟蹤,包括有關原始指令碼的資訊。

package T;
require Exporter;
@ISA = qw/Exporter/;
@EXPORT = qw/function/;
use Carp qw(cluck);
sub function {
   cluck "Error in module!";
}
1;

當從指令碼呼叫類似於下面這樣時 −

use T;
function();

它將產生以下結果 −

Error in module! at T.pm line 9
   T::function() called at test.pl line 4

更新於:2019-11-29

814 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始入門
廣告
© . All rights reserved.