By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,841 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,841 IT Pros & Developers. It's quick & easy.

Parsing function args in Getopt::Long style

P: n/a
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'};

# ....
}
Jan 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jan 11 '08 #2

P: n/a
"Yuri Shtil" <sh***@comcast.netwrote:
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/
Jan 11 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.