getOptions for object oriented Perl

A

a

Hi,

Since some parameters from @ARGV are for the child method. I need to process
some of these parameters in the method of the child class. But the
following code doesnt work. The GetOptions do not process the ARGV for the
parent class. How should I make it to work?

In parentClass
parseCommandLine(){
GetOptions(\%cmdLineArgs, "h","p=i", "k=s"")
}

In childClass
parseCommandLine(){
GetOptions(\%cmdLineArgs, "n=s", "t=i")
$self->SUPER::parseCommandLine();
}

Thanks
 
A

anno4000

a said:
Hi,

Since some parameters from @ARGV are for the child method. I need to process
some of these parameters in the method of the child class. But the
following code doesnt work.

"Doesn't work" is the most meaningless error description there is.
Please say what you expect it to do and what it does instead. Otherwise
we're left to guesswork.
The GetOptions do not process the ARGV for the
parent class. How should I make it to work?

That's how GetOptions works. It removes the keys and their values from
@ARGV for good. If you want to parse them again, you can localize @ARGV
before the call. However, GetOptions will then complain about the
options that are present in @ARGV, but are meant for the "other" call.
In the child class method:

sub parseCommandLine {
my $self = shift;
{
local @ARGV = @ARGV;
GetOptions( \ %cmdLineArgs, "h","p=i", "k=s"");
}
$self->SUPER::parseCommandLine();
}

I'm leaving it open where and how %cmdLineArgs is declared.

Normal practice is not to process @ARGV in a class (or module), but
do that in the main program. Then call appropriate methods to spread
the news.
In parentClass
parseCommandLine(){
GetOptions(\%cmdLineArgs, "h","p=i", "k=s"")
}

In childClass
parseCommandLine(){
GetOptions(\%cmdLineArgs, "n=s", "t=i")
$self->SUPER::parseCommandLine();
}

Your code above is not valid Perl. The "sub" keyword is missing before
the method definitions. The prototype (that's the '()' after the method
name) is bogus and should go. It is ignored with methods. Blocks
should be indented. Semicolons are missing between statements. It
wouldn't compile.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top