Subject: | extract_codeblock fat-comma parsing broken by over-eager quotelike { y => $y } |
For trying to parse a hashref, extract_codeblock looks superficially attractive. However, the quotelike parsing is too eager to match y => as the quotelike operator y=...=
So:
$ extract_codeblock '{ x => $x, y => $y}, { x => $x2, y => $y2 }'
$VAR1 = '{ x => $x, y => $y}, { x => $x2, y => $y2 }';
$VAR2 = '';
$VAR3 = '';
Whereas I'd have expected a behaviour more similar to:
$ extract_bracketed '{ x => $x, y => $y}, { x => $x2, y => $y2 }', '{}'
$VAR1 = '{ x => $x, y => $y}';
$VAR2 = ', { x => $x2, y => $y2 }';
$VAR3 = '';
I think the solution is to disambiguate '=>' differently, which seems to be what Perl itself does:
$ my $x = 'foo';
$ $x =~ s=<foo== # OK
$ $x =~ s=>foo== # NOT OK: Compile error: syntax error