The first problem is that you’re using (?:) to contain the alternation, and then using $+ to check the captured value. Which captured value? There’s no captured value. You need to move the capturing parens from the split to the the qr//.
Next, do you really need a deferred pattern there? I’d write it like so:
qr/($QUOTED|$NUM)(?(?{ '.' eq $+ })$FAIL)/;
(which of course implies variables rather than constants.)
Now given that, you get a zero-length match:
$VAR1 = [
'name => ',
'"foo"',
', fav',
'',
'.num => ',
'3'
];
So obviously a match against the lone dot was prevented, but $NUM succeeds in matching nothing. Easily fixed:
qr/($QUOTED|$NUM)(?(?{ '.' eq $+ or not length( $+ ) })$FAIL)/;
Result:
$VAR1 = [
'name => ',
'"foo"',
', fav.num => ',
'3'
];
Q.E.D.
But for practical use I’d prefer tye’s approach, which forces failure without squandering effort.
Makeshifts last the longest.
In reply to Re: Forcing a regex to fail
by Aristotle
in thread Forcing a regex to fail
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |