#!/usr/bin/perl -w use strict; use Text::Balanced qw(extract_codeblock); for ( '{ $h{x} = "}" }', '{ $h{s} = "}" }', '{ $h{s} = 1; print "{oops}" }', '{ $h{m} = "}" }', '{ $h{y} = "}" }', '{ $h{tr} = "}" }', '{ $h{qq} = "}" }', '{ $h{qr} = "}" }', '{ $h{qw} = "}" }', '{ $h{qx} = "}" }', ){ my ($e,$r) = extract_codeblock $_; print "Code: $_\nExtracted: $e\nRemainder: $r\n\$\@: $@\n\n"; } #### Code: { $h{x} = "}" } Extracted: { $h{x} = "}" } Remainder: Code: { $h{s} = "}" } Extracted: Remainder: { $h{s} = "}" } Code: { $h{s} = 1; print "{oops}" } Extracted: Remainder: { $h{s} = 1; print "{oops}" } Code: { $h{m} = "}" } Extracted: Remainder: { $h{m} = "}" } Code: { $h{y} = "}" } Extracted: Remainder: { $h{y} = "}" } Code: { $h{tr} = "}" } Extracted: Remainder: { $h{tr} = "}" } #### #!/usr/bin/perl -w -s use strict; use Parse::RecDescent; my $parser; $parser = Parse::RecDescent->new(q({my %foo} rule:"foo"{$foo{x}="}";})); $parser = Parse::RecDescent->new(q({my %foo} rule:"foo"{$foo{s}="}";})); $parser = Parse::RecDescent->new(q({my %foo} rule:"foo"{$foo{y}="}";})); $parser = Parse::RecDescent->new(q({my %foo} rule:"foo"{$foo{m}="}";})); $parser = Parse::RecDescent->new(q({my %foo} rule:"foo"{$foo{tr}="}";})); #### Parse::RecDescent: Treating "{my %foo}" as an action Parse::RecDescent: Treating "rule:" as a rule declaration Parse::RecDescent: Treating ""foo"" as an interpolated literal terminal Parse::RecDescent: Treating "{$foo{x}="}";}" as an action printing code (4142) to RD_TRACE Parse::RecDescent: Treating "{my %foo}" as an action Parse::RecDescent: Treating "rule:" as a rule declaration Parse::RecDescent: Treating ""foo"" as an interpolated literal terminal printing code (3618) to RD_TRACE Parse::RecDescent: Treating "{my %foo}" as an action Parse::RecDescent: Treating "rule:" as a rule declaration Parse::RecDescent: Treating ""foo"" as an interpolated literal terminal printing code (3618) to RD_TRACE Parse::RecDescent: Treating "{my %foo}" as an action Parse::RecDescent: Treating "rule:" as a rule declaration Parse::RecDescent: Treating ""foo"" as an interpolated literal terminal printing code (3618) to RD_TRACE Parse::RecDescent: Treating "{my %foo}" as an action Parse::RecDescent: Treating "rule:" as a rule declaration Parse::RecDescent: Treating ""foo"" as an interpolated literal terminal printing code (3618) to RD_TRACE