Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   getOptions for object oriented Perl (http://www.velocityreviews.com/forums/t901943-getoptions-for-object-oriented-perl.html)

a 02-21-2007 07:57 AM

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



anno4000@radom.zrz.tu-berlin.de 02-21-2007 04:02 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57