Always use strict and warnings


Always start your Perl code with:


use strict;
use warnings;

Example code that generates warning:

Add code everywhere to avoid warnings:


examples/advanced-perl/code_with_warnings.pl
#!/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.