Parsing function args in Getopt::Long style

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( [at] _);

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

# ....
}
Yuri Shtil [ Fr, 11 Januar 2008 22:11 ] [ ID #1905790 ]

Re: Parsing function args in Getopt::Long style

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( [at] _);
>
> my $v1 = $options->{'p1'};
>
> # ....
> }

Maybe something like this?

sub foo {
local [at] ARGV = [at] _;
$r = GetOptions(...);
...
}

M4
Martijn Lievaart [ Fr, 11 Januar 2008 22:40 ] [ ID #1905794 ]

Re: Parsing function args in Getopt::Long style

"Yuri Shtil" <shtil [at] comcast.net> 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( [at] _);


my %options = [at] _;

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

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


--
John

http://johnbokma.com/perl/
John Bokma [ Sa, 12 Januar 2008 00:03 ] [ ID #1905801 ]

Re: Parsing function args in Getopt::Long style

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( [at] _);
>
> my $v1 = $options->{'p1'};
>
> # ....
> }

Maybe something like this?

sub foo {
local [at] ARGV = [at] _;
$r = GetOptions(...);
...
}

M4
Martijn Lievaart [ Fr, 11 Januar 2008 22:40 ] [ ID #1905821 ]

Re: Parsing function args in Getopt::Long style

"Yuri Shtil" <shtil [at] comcast.net> 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( [at] _);


my %options = [at] _;

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

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


--
John

http://johnbokma.com/perl/
John Bokma [ Sa, 12 Januar 2008 00:03 ] [ ID #1905824 ]
Perl » comp.lang.perl.misc » Parsing function args in Getopt::Long style

Vorheriges Thema: Question about arrays of hashes
Nächstes Thema: Testing CGI.pm-using code