in reply to use strict; and command line options

Dude, these guys who responded above obviously didn't understand your question, or were just too quick to answer without checking.

Anwyay, the solution is actually quite simple, you just need to add use vars qw($useTR);. Here's some sample code and example run:

#!/usr/bin/perl use strict; use vars qw($a $b); print "a: $a\n"; print "b: $b\n";
and sample run:
[me@host]$ perl -s tmp.pl -a a: 1 b: [me@host]$
OK, though... all that being said I'd still recomend using Getopt::Long instead of just the -s switch, if for no other reason than that the user has to supply "-s" before your script when they run it (yes, folks, before you jump on me... I tested putting -s in the shebang line and it didn't work... which, frankly, shocked the heck out of me... maybe it's a bug in 5.005_03, or maybe it's a "feature").
------------ :Wq Not an editor command: Wq

Replies are listed 'Best First'.
Re: Re: use strict; and command line options
by ysth (Canon) on Feb 11, 2004 at 05:29 UTC
    -s on the shebang line had a bug and was fixed (I think) in 5.8.0.

    Update: the bug only applied when foo.pl was run as perl foo.pl, not ./foo.pl.

      Nice. I never use it myself (I always use Getopt::Long for switches)... I only looked it up to answer this guy's question.
      ------------ :Wq Not an editor command: Wq
Re: Re: use strict; and command line options
by etcshadow (Priest) on Feb 11, 2004 at 05:28 UTC
    Erg... I spoke to soon about the -s switch not being honored on the shebang line... it's a little bit odder than that. It is honored if the script is invoked by the shebang, but not if it is invoked by a direct call to the interpretter (and, thus, that the shebang line just gets parsed by the interpretter):
    [me@host]$ cat t2.pl #!/usr/bin/perl -s use strict; use vars qw($a $b); print "a: $a\n"; print "b: $b\n"; [me@host]$ perl t2.pl -a a: b: [me@host]$ ./t2.pl -a a: 1 b: [me@host]$
    This is really weird, as most switches should not behave differently if the script is invoked by the shebang rather than by calling the interpretter explicitly... Really frickin' odd.
    ------------ :Wq Not an editor command: Wq