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

Always use strict and warnings

  • strict
  • warnings

Always start your Perl code with:

use strict;
use warnings;

Example code that generates warning:

Add code everywhere to avoid warnings:

#!/usr/bin/perl 
use strict;
use warnings;

my $total;

add();

print "$total\n";


sub add {
    $total = $total + rand();
}

# triggers:
# Use of uninitialized value in addition (+)
#   at examples/advanced/code_with_warnings.pl line 14.
# or in 5.10
# Use of uninitialized value $total in addition (+)
#   at examples/advanced/code_with_warnings.pl line 14.