Getopt:Long arguments that are not (options or option values)

Discussion in 'Perl Misc' started by nahum_barnea, Sep 21, 2010.

  1. nahum_barnea

    nahum_barnea Guest

    Hi Group.
    I use Perl "use Getopt::Long;" .
    Now, I know how to get command line options and their values.
    But I want to get into a Perl array all the command line arguments
    that are NOT options and NOT values.

    For example:

    ../myscript.pl -f option_val_of_f -g option_val_of_g arg1 arg2 arg3

    I would like to get a Perl array with arg1,arg2,arg3 .

    Do you know how to do such stuff?

    Thanks,
    NAHUM
     
    nahum_barnea, Sep 21, 2010
    #1
    1. Advertising

  2. On 21.09.2010 19:33, nahum_barnea wrote:
    > Hi Group.
    > I use Perl "use Getopt::Long;" .
    > Now, I know how to get command line options and their values.
    > But I want to get into a Perl array all the command line arguments
    > that are NOT options and NOT values.
    >
    > For example:
    >
    > ./myscript.pl -f option_val_of_f -g option_val_of_g arg1 arg2 arg3
    >
    > I would like to get a Perl array with arg1,arg2,arg3 .


    Look at @ARGV.

    Wolf
     
    Wolf Behrenhoff, Sep 21, 2010
    #2
    1. Advertising

  3. nahum_barnea

    Guest

    On Sep 21, 11:33 am, nahum_barnea <> wrote:
    > I use Perl "use Getopt::Long;" .
    > Now, I know how to get command line options and their values.
    > But I want to get into a Perl array all the command line arguments
    > that are NOT options and NOT values.
    >
    > For example:
    >
    > ./myscript.pl -f option_val_of_f -g option_val_of_g   arg1 arg2 arg3
    >
    > I would like to get a Perl array with arg1,arg2,arg3  .



    Just check @ARGV after you call GetOptions(). Calling GetOptions()
    will cause the options (and their values) to be removed from the @ARGV
    array, leaving only the non-option-arguments behind.

    So then, @ARGV has exactly what you're looking for (but only AFTER
    you call GetOptions()).

    I hope this helps, Nahum.

    -- Jean-Luc
     
    , Sep 21, 2010
    #3
  4. nahum_barnea <> writes:

    > Now, I know how to get command line options and their values.
    > But I want to get into a Perl array all the command line arguments
    > that are NOT options and NOT values.


    Read the documentation for the module and look for the 'pass_through'
    configuration option.

    //Makholm
     
    Peter Makholm, Sep 21, 2010
    #4
    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. Replies:
    4
    Views:
    841
    Tom Anderson
    Dec 21, 2005
  2. Rocky Zhou
    Replies:
    3
    Views:
    338
    Steven Bethard
    Mar 18, 2007
  3. Sunil
    Replies:
    5
    Views:
    365
    Bart Lateur
    Aug 14, 2003
  4. Sunil
    Replies:
    8
    Views:
    164
    Benjamin Goldberg
    Sep 2, 2003
  5. mothra
    Replies:
    3
    Views:
    386
    Shawn Corey
    Dec 2, 2004
Loading...

Share This Page