in reply to Re^2: Recognizing Perl in text
in thread Recognizing Perl in text

With a clever strategy it's possible to significantly limit the number of possible chunks to check!

Simply start checking the most indented line and successively add surrounding lines.

for my $foo (@foo) { # 8 fails for my $bar (@$foo) { # 6 fails push @{ $self->{results} }, # 5 works { # 3 fails baz => foo( $bar->{baz}, # 2 works $bar->{quux}[1] ) # 1 fails }; # 4 works } # 7 works } # 9 works

like this the overhead for identifying n lines of code is (statistically) at most linear!

UPDATE: And it's still possible to rely on the existence of trailing semicolons or braces before running a syntax check.

Cheers Rolf