Connecting Tech Pros Worldwide Help | Site Map

Parsing function args in Getopt::Long style

  #1  
Old January 11th, 2008, 09:15 PM
Yuri Shtil
Guest
 
Posts: 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'};

# ....
}


  #2  
Old January 11th, 2008, 09:45 PM
Martijn Lievaart
Guest
 
Posts: n/a

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
  #3  
Old January 11th, 2008, 11:05 PM
John Bokma
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
Python source colorizer M.E.Farmer answers 1 July 18th, 2005 02:35 PM