Connecting Tech Pros Worldwide Forums | Help | Site Map

Parsing function args in Getopt::Long style

Yuri Shtil
Guest
 
Posts: n/a
#1: Jan 11 '08
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'};

# ....
}



Martijn Lievaart
Guest
 
Posts: n/a
#2: Jan 11 '08

re: Parsing function args in Getopt::Long style


On Fri, 11 Jan 2008 13:11:23 -0800, Yuri Shtil wrote:
Quote:
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
John Bokma
Guest
 
Posts: n/a
#3: Jan 11 '08

re: Parsing function args in Getopt::Long style


"Yuri Shtil" <shtil@comcast.netwrote:
Quote:
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 );


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

my %options = @_;
Quote:
my $v1 = $options->{'p1'};
my $v1 = $options{ '-p1' );


--
John

http://johnbokma.com/perl/
Closed Thread


Similar Perl bytes