in reply to Re: Re: Poor's man command line arguments
in thread Poor's man command line arguments

How does the use of $foo as a switch jive with the recomendation to use strict; for all programs?

In short, it doesn't - The -s argument is meant for quick-and-nasty argument handling, the usage of these variable names causing explicit package name errors when employed with strict.

For example:

rob@budapest:/home/rob# cat test.perl #!/usr/bin/perl -s use strict; print "bar!\n" if ($foo); rob@budapest:/home/rob# ./test.perl -foo Variable "$foo" is not imported at ./test.perl line 5. Global symbol "$foo" requires explicit package name at ./test.perl lin +e 5. Execution of ./test.perl aborted due to compilation errors.
If however, strict is turned off within the scope where these variables are employed, everything is happy once more. Eg.

rob@budapest:/home/rob# cat test.perl #!/usr/bin/perl -s use strict; { no strict; print "bar!\n" if ($foo); } rob@budapest:/home/rob# ./test.perl -foo bar!

 

perl -e 'print+unpack("N",pack("B32","00000000000000000000000111100000")),"\n"'

Replies are listed 'Best First'.
Re: Re: Re: Re: Poor's man command line arguments
by runrig (Abbot) on Nov 14, 2002 at 02:20 UTC
    If however, strict is turned off within the scope where these variables are employed, everything is happy once more.

    Or use 'use vars' or 'our':

    #!/usr/bin/perl -s use strict; use warnings; use vars qw($foo); print "bar!\n" if $foo;