in reply to Parser Performance Question

Unrelated to your performance question, but this

>  qr/ " (?: [^"] | \\" )* " /x;

is broken code.

Try to guess what it's supposed to do, and then try to test what it really does, and you'll see why testing is important.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: Parser Performance Question
by choroba (Cardinal) on Oct 05, 2017 at 11:57 UTC
    Please, stop talking in riddles. Do you mean "a\\"b"?
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      > Please, stop talking in riddles.

      Riddles are an efficient instrument for motivation in didactics. =)

      For instance a friend of mine spends loads of time in hacker competitions... ;-)

      > Do you mean "a\\"b"?

      What do you think? xD

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      update

      DB<103> '"a\\"b"' =~ / " (?: [^"] | \\" )* " /x ; print $& # + nonsense "a\" DB<104> '"a\\"b"' =~ / " (?: \\" | [^"] )* " /x ; print $& # + better "a\"b" DB<105> '"a\\"b"' =~ / " (?: \\\\ | \\" | [^"] )* " /x ; print $& # + best "a\"b"

      Why #nonsense? Because the or-branch will never match, no matter which input.

        The last two are still incorrect, as q< \\" > will be parsed as an escaped quote. /" (?: [^"\\] | \\. )* "/sx is the bestest solution :-P

        Edit: except when I'm an idiot and confuse (?= for (?: