![]() |
getOptions for object oriented Perl
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 |
Re: getOptions for object oriented Perl
a <a@mail.com> wrote in comp.lang.perl.misc:
> 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 |
| All times are GMT. The time now is 11:55 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.