On Jan 13, Eric Beaudoin said:

>Because of the very interesting article by Randall in a recent SysAdmin,
>I've start using the very nice Parse::RecDescent module worte by Damian
>Conway. This thing rocks. See
>http://www.stonehenge.com/merlyn/UnixReview/col40.html for the article.

*cough* Randal *cough*

>  if($ruletype eq 'EQUIPMENT')
>  {
>      defined $parser->lst_equipment(join('',<THEFILE>)))
>        or print  "!!! Unable to parse.\n";
>  }
>  elsif($ruletype eq 'PCC')
>  {
>      defined $parser->pcc(join('',<THEFILE>)))
>        or print  "!!! Unable to parse.\n";
>  }
>  elsif ...
>
>I have a hash that has the rule information. It looks like this:
>
>my %filetyperules = (
>        PCC         => 'pcc',
>        EQUIPMENT   => 'lst_equipment',
>        ...
>                    );
>
>Is there a way to use $filetyperules{$ruletype} directly to call the
>$parser->method whitout having to do all these if{ }elsif{ }elsif{ }...

Yes, there is:

  my $method = $filetyperules{$ruletype};
  defined($parser->$method(join '', <THEFILE>))
    or print "!!! Unable to parse.\n";

Nifty, eh?

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to