in reply to Re: use strict; and command line options
in thread use strict; and command line options

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.
  • Comment on Re: Re: use strict; and command line options

Replies are listed 'Best First'.
Re: Re: Re: use strict; and command line options
by Roger (Parson) on Feb 11, 2004 at 03:17 UTC
    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
        Thanks for the correction. I should have checked the perl usage more carefully. *blush*.

Re: Re: Re: use strict; and command line options
by Vautrin (Hermit) on Feb 11, 2004 at 03:12 UTC
    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.