Does Perl combine multiple REs into a single automaton?

From: Clint Olsen (clint_at_0lsen.net)
Date: 06/28/04


Date: Mon, 28 Jun 2004 17:04:23 GMT

Hi:

I posted earlier about how to speed up writing lexical analyzers in Perl.
With that effort in mind, I was curious to know if Perl combines multiple
patterns like:

if (/pat/) {
} elsif (/pat1/) {
...
} elsif (/pat2/) {
...
...
...
} else {
}

so that pat[\d]+ are in a sense combined via alternation with each branch
working like embedded action code?

The reason why I ask is that someone suggested I try to do this manually in
order to help speed up the pattern matching process (presumably using the
"(?{ code })" feature documented in perlre. Is it really faster to do it
this way?

When I'm in the debugger in Perl, I've noticed that the execution path gets
sort of muddied. I don't see Perl executing each match as a separate
statement. It's as if it jumps right to the code for the pattern match.
If that's the case, then there's not much of a compelling argument to embed
action code and cobmine REs.

Thanks,

-Clint



Relevant Pages

  • Re: pattern matching question - please help
    ... Thanks for your detailed email and for your time. ... read on Perl did not mention anything about first and ... >> the pattern match ... a single character (basically, see references ...
    (perl.beginners)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)
  • FAQ 6.23 How do I match a regular expression thats in a variable?
    ... How do I match a regular expression that's in a variable? ... We don't have to hard-code patterns into the match operator (or anything ... have the pattern in $regex, you use that variable in the match operator. ... and the pattern still has to be valid or Perl will complain. ...
    (comp.lang.perl.misc)