Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Parsing function args in Getopt::Long style

Reply
Thread Tools

Parsing function args in Getopt::Long style

 
 
Yuri Shtil
Guest
Posts: n/a
 
      01-11-2008
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'};

# ....
}


 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      01-11-2008
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
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      01-11-2008
"Yuri Shtil" <(E-Mail Removed)> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forwarding Args&&... vs forwarding Args... Andrew Tomazos C++ 5 01-05-2012 11:15 PM
C++0x -- fun(Args&...) and fun(Args const&...) er C++ 2 12-20-2010 07:52 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments