in reply to use strict; and command line options

You have to declare your variables before using them.
use strict; my $useTR = "SOMETHING"; # or: our $useTR = "SOMETHING"; # or: use vars qw/ $useTR /; if ($useTR) { print "useTR = $useTR\n"; }

Replies are listed 'Best First'.
Re: Re: use strict; and command line options
by hehenoobhehe (Novice) on Feb 11, 2004 at 03:02 UTC
    Well, my objectve here is to provide MY own switches for the PERL program and as I understand it:If an option is specified , the scalar variable whose name is the same as the option is automatically set to 1 before program execution begins. By providing the variable with a value I am unable to read the command line option that may have been provided byu the user. Note this is an option, not an argument. Thanks.
      That's not how you use command line options.

      There are many ways to retrieve command-line parameters, below are two that I use often:
      # method 1 use strict; die "you must provide command-line parameters" if ! @ARGV; print "command-line option: $_\n" for @ARGV; # method 2 use strict; use Getopt::Long; GetOptions ( 'useTR' => \{ my $useTR = 0 }, ); unless ( defined $useTR ) { die "Usage: $0 -useTR"; } # Then you use the $useTR variable onwards

        Thanks I now understand that i will have to use Getopt::Long and GetOptions. Thanks again.
        That's not how you use command line options.
        Says who? What's the -s for then? Just because its usuage is rare doesn't mean it's not supported and that you have to roll your own @ARGV parsing.

        Abigail

        perl -wlseprint -- -_=Just\ another\ Perl\ Hacker
      The @ARGV array holds all command line options. You may want to process it using your favorite flavor of loop.

      Want to support the EFF and FSF by buying cool stuff? Click here.