4 ms·
To whomever is thinking "but JSON is not regular!", note that that regex is not a regular expression (Perl has a very liberal definition of regexes). Perl rege
by ot 13y ago
To whomever is thinking "but JSON is not regular!", note that that regex is not a regular expression (Perl has a very liberal definition of regexes).
Perl regexes can be recursive: the operator $^R means "match here the whole regex itself", making the matching algorithm a full recursive descent parser. I suspect that parsing speed wouldn't be too bad because JSON is LL(1), so the parser shouldn't backtrack.
I don't think that the author is suggesting to use this in any useful code, he's just showing a cool hack. It kind of resonates well with the Perl aesthetics of short, "clever" code with as little as possible dependencies (and a fascination for regexes).
- fulafel 13y agoThe original Randal Schwartz post (http://www.perlmonks.org/?node_id=995856 http://www.perlmonks.org/?node_id=995856) says it was infact code for a customer app.