The cluck Function in Perl

PERLServer Side ProgrammingProgramming Scripts

The cluck function in Perl is a sort of supercharged carp, it follows the same basic principle but also prints a stack trace of all the modules that led to the function being called, including the information on the original script.

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

When called from a script like below −

use T;
function();

It will produce the following result −

Error in module! at T.pm line 9
   T::function() called at test.pl line 4
raja
Updated on 29-Nov-2019 11:46:36

Advertisements