--- "Adam D. Lopresto" <[EMAIL PROTECTED]> wrote: > I propose that since the empty pattern is no longer legal (and > about time), we use "|" in patterns to indicate alternation without > preference, and "||" to indicate "try the first, then the second, > etc".
Hmm.... A neat idea, but can you elaborate on when it would matter? > So > "cat dog fox" ~~ /( fox | dog | cat )/; > might match any of the three, and in fact is quite likely to match > cat (since scanning the string could be a very long process), but > "cat dog fox" ~~ /( fox || dog || cat )/; > would be guaranteed to first try fox, then if that fails backtrack > and try dog, and if that fails backtract to try cat. The choice of > symbols parallels the junction and short-circuiting or operators, > and in most cases when an alternation is specified, the programmer > has no preference among the alternatives (indeed, in most cases only > would could match anyway), so it seems silly to force the engine to > prefer the first one. I thought the requirement to prefer the first was largely an optimization, so that it could bail when it had a match without continuing to search. ("Wouldn't you know, it was in the *last* place I looked for it!") Are you proposing a more DFA-ish behavior, maybe? Some programs actually embad a DFA for a quick "does it match?" as *well* as an NFA for pulling out backreferences once the DFA finds a hit, but I doubt anybody is planning to embed a pre-matching DFA in Perl (if so, somebody please tell me now). > I'm imagining that in the first example, the implementation would > probably build an FSA and process each letter as it comes, while the > second would rely on backtracking. Sounds like DFA/NFA to me.... > What think you all? Dunno. Would swell the footprint some, but might have some merit. DFA's are generally faster, I believe, but P5's NFA is optimized to a beautiful degree. Might be possible just by tuning the engine some more, but then the codebase is still swelling.... Dan? Parrot's pure NFA, right? __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - File online, calculators, forms, and more http://tax.yahoo.com