Monday, January 6, 2014

How to enable warnings for Perl execution

1. Enable warnings from command line: perl -w

2. Through Shebang line: #!/usr/bin/perl -w

However this doesn't work in case of #!/usr/bin/env perl -w because env tries to treat "perl -w" as single argument.

3. use warnings - However this has lexical implications and only applies to current code

4. BEGIN{
$^W = 1
}

BEGIN block is executed during compilation and hence this sets warnings switch to true and applies to all the scripts that get executed/imported during this execution.