Re: parsing command line arguments multiple times



On 4/29/05, John Doe <security.department@xxxxxxxx> wrote:
>
> Am Freitag, 29. April 2005 10.19 schrieb lohit:
> > On 4/29/05, John Doe <security.department@xxxxxxxx> wrote:
> > > Am Freitag, 29. April 2005 09.19 schrieb lohit:
> > > > On 4/29/05, lohit <lohit.vijayarenu@xxxxxxxxx> wrote:
> > > > > Hi,
> > >
> > > Hi
> > >
> > > > > i have a requirement, as in based on one command line option, the
> > > > > rest of the arguments change for the same script.
> > > > > eg: script could be called in either of the ways
> > > > > script1 -option1 -option2 adfas -option3
> > > > > script -option1 -option4
> > > > > my question is
> > > > > 1. how do we get the option1 alone from GetOptions function
> > > > > 2. can i call GetOptions multiple times?
> > > > > how would you handle such situation
> > > > > thanks in advance for the help!!
> > > >
> > > > ok, i see that only one option could be parse with GetOptions
> > >
> > > Are there reasons not to use GetOpt::Std or GetOpt::Long?
> > > Could you provide some code?
> >
> > i am fine with any GetOpt as long as it solves my problem. this is the
> > problem i have been having.
> > script usage is:
> > script.pl -checkflag -option1 value1 -option2 value2
> > now my problem is i need to check only '-checkflag' flag. rest would be
> > parsed in second run.
> > now if the first run i parse it something like
> > &GetOptions('checkflag' => \$check_flag);
> > if ($checkflag)
> > {
> > do somethign here.....
> > }
> > but perl throws an error,
> > Unknow argument option1
> > Unknow argument option2
> > how do i get rid of them, or any other solution?
> > thanks!
> >
> > > and for the
> > >
> > > > next run i could copy back a saved version of @ARGV.
> > > > but while i am processin any one options, i get an error message
> saying
> > > > *Unknow option* * *for the other unused options. how do i get rid of
> > >
> > > this?
>
> Hi lohit
>
> With the modules I mentoned, you can parse all provided options with one
> sub
> call. The handling of the values is separated from that.
>
> Here is a snippet of one of my scripts;
> by reading the man pages you can adapt it to your needs:
>
> === beg ===
>
> use strict;
> use warnings;
> use Getopt::Long;
>
> # default values for all possible options:
> #
> my $opt_surveyname='';
> my $opt_fbname='';
>
> # slurp all cmdline opts into the corresponding vars:
> #
> GetOptions (
> 'surveyname=s'=>\$opt_surveyname,
> 'fbname=s'=>\$opt_fbname,
> );
>
> # Check correct options / combinations / whatever
> #
> &usage () unless $opt_surveyname and $opt_fbname;
>
> ###
> ### Here your code to process the provided option values
> ###
>
> sub usage {
> print <<EOF;
> ...
> EOF
> exit;
> }
>
> === end ===
>
> The script is called
>
> script --surveyname=foo --fbname=bar

thanks joe,
lets assume we add an option -checkflag to your script
script -checkflag --surveyname=foo --fbname=bar
now if i specify -checkflag , we have to parse surveryname and fbname
lets assume i do not pass checkflag , then i would like to invoke script
soemthing like this
script --surveyname==foo --username=foobar
so, checkflag is kind of check for different *sets* of arguments.
so i need to parse arguments multiple times..
how would you go about in this situation
thanks for the help!

joe
>
> > > --
> > > To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
> > > For additional commands, e-mail: beginners-help@xxxxxxxx
> > > <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
> For additional commands, e-mail: beginners-help@xxxxxxxx
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


Relevant Pages

  • Re: parsing command line arguments multiple times
    ... >>> i am fine with any GetOpt as long as it solves my problem. ... >> With the modules I mentoned, you can parse all provided options with one ... > thanks joe, ... > lets assume we add an option -checkflag to your script ...
    (perl.beginners)
  • Re: Parsing strings via shell vars?
    ... My shell scripting must be getting rusty and a quick google isn't ... > I need to find a way to parse a shell variable rather than a file, ... > it's basically using a few system files to determine what variant of *nix ... > further filesystem checks to verify what specific flavor of *nix the script ...
    (comp.unix.shell)
  • Re: [KSH 88] How to use set -A when first value is -x
    ... : optional args. ... It uses getopts to parse the options (I guess that was ... obvious) and a for x in $@ to parse out the mandatory arguments. ... of the script. ...
    (comp.unix.shell)
  • Re: Help with system seeming to return too soon...
    ... > So to solve this problem I have to parse the vpnenv.sh script to ... > extract all the environment variables that are being set? ... you can then parse the output of this mini-script to set %ENV. ...
    (comp.lang.perl.misc)
  • Re: Can I generate an event with script?
    ... meaning since you will need to handle the event and assumedly construct ... In the called page you will need to get window.location.search and parse out ... if your iframe is contained in your main page and the iframe source is ... > I want to generate an event in my script. ...
    (microsoft.public.scripting.jscript)