getOptions for object oriented Perl

Discussion in 'Perl Misc' started by a, Feb 21, 2007.

  1. a

    a Guest

    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, Feb 21, 2007
    #1
    1. Advertising

  2. a

    -berlin.de Guest

    a <> 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
     
    -berlin.de, Feb 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    438
    Bruno Desthuilliers
    May 26, 2008
  2. rolo
    Replies:
    3
    Views:
    189
    Robert Klemme
    Apr 9, 2004
  3. Moti Shtrobach

    Using GetOptions twice in the script

    Moti Shtrobach, Nov 25, 2003, in forum: Perl Misc
    Replies:
    6
    Views:
    154
    Johan Vromans
    Dec 3, 2003
  4. perl_newbie
    Replies:
    7
    Views:
    190
    A. Sinan Unur
    Jun 2, 2005
  5. Replies:
    2
    Views:
    183
    Brian McCauley
    Dec 22, 2005
Loading...

Share This Page