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. Advertisements

  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. Advertisements

  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. Advertisements

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. Dan Rawson
    Replies:
    4
    Views:
    721
    Jeff Epler
    Sep 19, 2003
  2. Replies:
    4
    Views:
    945
    Tom Anderson
    Dec 21, 2005
  3. Rocky Zhou
    Replies:
    3
    Views:
    454
    Steven Bethard
    Mar 18, 2007
  4. Oliver Graeser
    Replies:
    10
    Views:
    819
    Oliver Graeser
    Sep 26, 2008
  5. Sunil
    Replies:
    5
    Views:
    539
    Bart Lateur
    Aug 14, 2003
  6. Sunil
    Replies:
    8
    Views:
    354
    Benjamin Goldberg
    Sep 2, 2003
  7. mothra
    Replies:
    3
    Views:
    652
    Shawn Corey
    Dec 2, 2004
  8. Perl Learner
    Replies:
    1
    Views:
    316
    Jim Keenan
    Jun 13, 2005
Loading...