Parsing function args in Getopt::Long style

Parsing function args in Getopt::Long style

am 11.01.2008 22:11:23 von 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'};

# ....
}

Re: Parsing function args in Getopt::Long style

am 11.01.2008 22:40:27 von Martijn Lievaart

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

Re: Parsing function args in Getopt::Long style

am 11.01.2008 22:40:27 von Martijn Lievaart

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

Re: Parsing function args in Getopt::Long style

am 12.01.2008 00:03:19 von John Bokma

"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);

^ 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/

Re: Parsing function args in Getopt::Long style

am 12.01.2008 00:03:19 von John Bokma

"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);

^ 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/