Parsing function args in Getopt::Long style

Discussion in 'Perl' started by Yuri Shtil, Jan 11, 2008.

  1. Yuri Shtil

    Yuri Shtil Guest

    Is there a module to parse named function parameters in Getopt::Long style?

    What I have in mind is something like:

    # Call function
    &foo('-p1' -> $v1, '-p2' => $v2);

    #Define function
    sub foo {
    my $options = PARSER(@_);

    my $v1 = $options->{'p1'};

    # ....
    }
    Yuri Shtil, Jan 11, 2008
    #1
    1. Advertising

  2. On Fri, 11 Jan 2008 13:11:23 -0800, Yuri Shtil wrote:

    > Is there a module to parse named function parameters in Getopt::Long
    > style?
    >
    > What I have in mind is something like:
    >
    > # Call function
    > &foo('-p1' -> $v1, '-p2' => $v2);
    >
    > #Define function
    > sub foo {
    > my $options = PARSER(@_);
    >
    > my $v1 = $options->{'p1'};
    >
    > # ....
    > }


    Maybe something like this?

    sub foo {
    local @ARGV = @_;
    $r = GetOptions(...);
    ...
    }

    M4
    Martijn Lievaart, Jan 11, 2008
    #2
    1. Advertising

  3. Yuri Shtil

    John Bokma Guest

    "Yuri Shtil" <> wrote:

    > Is there a module to parse named function parameters in Getopt::Long
    > style?
    >
    > What I have in mind is something like:
    >
    > # Call function
    > &foo('-p1' -> $v1, '-p2' => $v2);


    ^ don't use & unless you know what it does.

    foo( '-p1' => $v1, '-p2' => $b2 );



    > #Define function
    > sub foo {
    > my $options = PARSER(@_);



    my %options = @_;

    > my $v1 = $options->{'p1'};


    my $v1 = $options{ '-p1' );


    --
    John

    http://johnbokma.com/perl/
    John Bokma, Jan 11, 2008
    #3
    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. Ken Varn
    Replies:
    2
    Views:
    627
    Ken Varn
    Jun 22, 2005
  2. dima
    Replies:
    9
    Views:
    699
    llewelly
    Sep 5, 2003
  3. Replies:
    3
    Views:
    491
    David Eppstein
    Sep 17, 2003
  4. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    688
    Pierre Fortin
    Sep 18, 2004
  5. mothra
    Replies:
    3
    Views:
    342
    Shawn Corey
    Dec 2, 2004
Loading...

Share This Page