Reputation: 118128
I remember seeing some comment somewhere that
use warnings;
use strict;
was preferable (rather than use'ing strict
first, as I was wont to do). Is my memory correct? Does the order matter and, if it does, in what way?
Upvotes: 11
Views: 832
Reputation: 118128
I thought, maybe, on Perl 5.8.9 and older where strict
does not warn when you use Strict
on case insensitive file systems, having warnings
first would help. I built 5.8.9 on my Windows XP system and it does not:
C:\Temp> cat t.pl
use warnings;
use Strict;
C:\Temp> c:\opt\perl-5.8.9\bin\perl.exe t.pl
C:\Temp>
That was a shot in the dark. I am led to conclude that so long as there are no intervening statements, the order is immaterial.
Upvotes: 3
Reputation: 107040
Simple: If you do use strict
before you do use warnings
, you won't get a warning if you're using use strict
wrong. DUH!
Actually, I've always done it the other way. The anal retentive in me made me put the two pragmas alphabetically. I never knew there was a reason to do it one way or another.
Heck, perldoc use shows placing use strict
before use warnings
, and that's what I've seen in most of the official Perl examples.
I suspect there's a cultural reason. Originally in Perl, to use warnings, you use to use
#! /usr/bin/perl -W
on the first line of your program. The use strict
pragma came later, and only later was use warnings
a pragma. Thus, programs (for a while) were written as:
#! /usr/bin/perl -W
use strict;
When the -W
parameter fell out of fashion, you simply added use warnings
right below the shebang:
#! /usr/bin/perl
use warnings;
use strict;
One of the things I like about Stackoverflow is that you can learn new things you never knew before. I'd love to see if someone has an actual reason why it should be one way and not another.
Upvotes: 3
Reputation: 15813
I can't see how there is any technical reason for the order being significant. I always put use strict
first as it happens but for no reason other than I've always done that!
Upvotes: 6