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!";

When called from a script like below −

use T;

It will produce the following result −

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