|
From: a on 21 Feb 2007 02:57 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
From: Michele Dondi on 21 Feb 2007 04:37 On Wed, 21 Feb 2007 07:57:46 GMT, "a" <a(a)mail.com> wrote: >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 This does not make sense. You use GetOptions(), which seems to come from Getopt::Long. That processes @ARGV "once and forever". If some of the implied parameters affect things related "the child method" or whatever, just preprocess the command line arguments at the beginning of your script and pass the collected data say to the constructors for your objects or to suitable methods. Or else I plainly don't understand your question. In which case you would better post a minimal but complete example exhibiting what that you want and how it fails to give that to you, because I feel smell of XY here: http://perlmonks.org/?node=XY+problem Michele -- {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB=' ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_, 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
From: anno4000 on 21 Feb 2007 11:02 a <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
|
Pages: 1 Prev: Regex matching a integer in a line Next: FAQ 5.9 How can I use a filehandle indirectly? |