in reply to use warnings vs. -w

However, to round out the thought, if you do use the warnings pragma, make sure you require a specific version of Perl. Something like:
use 5.6.0; use warnings;

That way, someone else using your script on another machine doesn't have a nasty surprise. (Personally, I think every production-level script should demand a specific Perl version, even if you know what will happen. You never always know ... ever.)

Replies are listed 'Best First'.
Re: Re: use warnings vs. -w
by chipmunk (Parson) on Jun 09, 2001 at 01:31 UTC
    Version strings, the feature that allows you to write 5.6.0, were also added in 5.6.0. Thus: use 5.6.0; will fail in a strange way with older versions of perl: Can't locate 5.60 in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 .) at -e line 1.

    I find it quite frustrating that a feature that is supposed to handle issues of backward compatibility was updated in a non-backward compatible way. :(

    Here's the backward compatible way to require 5.6.0: use 5.006;

      Um, it is backward compatible, and it should be: require 5.006; It just isn't forward compatible, as few things are.

              - tye (but my friends call me "Tye")
        Actually, in this case it must be: use 5.006; require is a runtime statement, but if we're using 5.6.0 syntax we need the version check at compile time. Compare these two examples, one with require and one with use, and their results with perl5.005_03:
        #!perl require 5.006; use strict; our $var = 7; __END__ Global symbol "$var" requires explicit package name at tmp.pl line 4. Execution of tmp.pl aborted due to compilation errors.
        #!perl use 5.006; use strict; our $var = 7; __END__ Perl 5.006 required--this is only version 5.00503, stopped at tmp2.pl +line 1. BEGIN failed--compilation aborted at tmp2.pl line 1.
        I believe I was correct when I said 'non-backward compatible'; I was referring to the use of version strings with require/use, as in require 5.6.0;. That feature is forward compatible (future versions of perl5 will support version strings) but not backwards compatible (past versions of perl do not support version strings).