Why are use warnings; use strict; not default in Perl?

It’s for backwards compatibility. Perl 4 didn’t have strict at all, and there are most likely still scripts out there originally written for Perl 4 that still work fine with Perl 5. Making strict automatic would break those scripts. The situation is even worse for one-liners, many of which don’t bother to declare variables. Making one-liners strict by default would break probably millions of shell scripts and Makefiles out there.

It can’t be loaded automagically, because it adds restrictions, not features. It’s one thing to load IO::File when a method is called on a filehandle. But activating strict unless the code did something prohibited by strict is meaningless.

If a script specifies a minimum version of 5.11.0 or higher (e.g. use 5.012), then strict is turned on automatically. This doesn’t enable warnings, but perhaps that will be added in a future version. Also, if you do OO programming in Perl, you should know that using Moose automatically turns on both strict and warnings in that class.

Leave a Comment