Problem with Getopt

Discussion in 'Perl' started by Arvind Kumar, Nov 3, 2003.

  1. Arvind Kumar

    Arvind Kumar Guest

    Hi Guys,
    I am summarizing this problem with a example. Appreciate if someone
    could help me.

    Say, I have a wrapper shell script which calls a perl program. I want
    to pass the command line options to this perl program.

    In the Wrapper (TCSH) script, I have something like this
    set TEMP = "x y z";
    mytest.pl -t ${TEMP};
    ------------------------
    In the Perl program, I have something like this;
    (Only fragment shown)
    my $status = GetOpt::Long:GetOptions ('t|test=s' => \$temp_var);
    print "$temp_var \n";
    ---------------
    This prints only x and not all of the "x y z"
    I am new to Perl but reasonably good in scripting.. Please help me..

    Regards,
    Arvind Kumar
     
    Arvind Kumar, Nov 3, 2003
    #1
    1. Advertising

  2. Arvind Kumar

    Jim Gibson Guest

    In article <>, Arvind
    Kumar <> wrote:

    > Hi Guys,
    > I am summarizing this problem with a example. Appreciate if someone
    > could help me.
    >
    > Say, I have a wrapper shell script which calls a perl program. I want
    > to pass the command line options to this perl program.
    >
    > In the Wrapper (TCSH) script, I have something like this
    > set TEMP = "x y z";
    > mytest.pl -t ${TEMP};


    This is equivalent to the command line: 'mytest.pl -t x y z'
    Thus, 'x' is the value of the -t parameter. 'y' and 'z' are ignored by
    the '-t' option according to the normal syntax of command line options.

    > ------------------------
    > In the Perl program, I have something like this;
    > (Only fragment shown)
    > my $status = GetOpt::Long:GetOptions ('t|test=s' => \$temp_var);


    It's spelled 'Getopt' on my system!

    > print "$temp_var \n";
    > ---------------
    > This prints only x and not all of the "x y z"
    > I am new to Perl but reasonably good in scripting.. Please help me..
    >
    > Regards,
    > Arvind Kumar


    Your program is behaving normally. If you want to enter 'y' and 'z' as
    some type of command line option, you must tell Getopt about the
    additional options. If you really want to enter "x y z" as the
    parameter for the -t option, put it in quotes: mytest.pl -t "x y z"
    In your shell script, you need to do:

    mytest.pl -t "${TEMP}"
     
    Jim Gibson, Nov 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dima
    Replies:
    9
    Views:
    702
    llewelly
    Sep 5, 2003
  2. Ramiro Rodriguez

    getopt

    Ramiro Rodriguez, Oct 14, 2003, in forum: C++
    Replies:
    6
    Views:
    4,005
    Lorenzo Bettini
    Oct 17, 2003
  3. Joel VanderWerf

    gem install getopt problem

    Joel VanderWerf, Nov 18, 2005, in forum: Ruby
    Replies:
    4
    Views:
    106
    Joel VanderWerf
    Nov 18, 2005
  4. S

    Getopt::Std problem

    S, Feb 2, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    115
    Uri Guttman
    Feb 2, 2004
  5. Daniel Berger

    Getopt::Long and <> problem

    Daniel Berger, Feb 18, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    257
    Daniel Berger
    Feb 19, 2004
Loading...

Share This Page