Hi everyone,

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.

I created a big grammar and have a series of files to parse. Most file types are alike 
but they are different enough to require there own starting rules. When a $parser is 
created, the rules becomes method of the object $parser.

When parsing, I need to call the right rule so I do something like this:

  open THEFILE, "$file" or die "Can't open $file: $!";
  
  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 ...
      
  close THEFILE;

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{ }...

Thanks in advance for any clues on this.


-----------------------------------------------------------
Éric Beaudoin                <mailto:[EMAIL PROTECTED]>


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

Reply via email to