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

  2. Maybe something like this?

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

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

  3. Yuri Shtil

    John Bokma Guest

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

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



    my %options = @_;
    my $v1 = $options{ '-p1' );
     
    John Bokma, Jan 11, 2008
    #3
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.