Parsing function args in Getopt::Long style

Y

Yuri Shtil

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'};

# ....
}
 
M

Martijn Lievaart

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
 
J

John Bokma

Yuri Shtil said:
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' );
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top