The cluck Function in Perl


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

Updated on: 29-Nov-2019

698 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements