Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Carp

  • Carp
  • carp
  • croak
It is better to use croak and carp instead of die and warn.
#!/usr/bin/perl
use strict;
use warnings;

use Module;

Module::f("x");  # Parameter needs to be a number at Module.pm line 10.

Module::g("x");  # Parameter needs to be a number at carp.pl line 8

Module::h("x");
# Parameter needs to be a number at Module.pm line 24
#        Module::h('x') called at carp.pl line 9
package Module;
use strict;
use warnings;

use Carp qw(carp cluck);

sub f {
    my ($x) = @_;
 
    warn "Parameter needs to be a number" if $x =~ /\D/;
    return $x;
}

sub g {
    my ($x) = @_;
 
    carp "Parameter needs to be a number" if $x =~ /\D/;
    return $x;
}

sub h {
    my ($x) = @_;
 
    cluck "Parameter needs to be a number" if $x =~ /\D/;
    return $x;
}


1;