in reply to Matching Perl Keywords
It is often said that "only Perl can parse Perl". The reason that this is said, and it is true, is that the ecclectic and rich synstax of Perl makes it impossible to generate simple and robust parsing solutions.
The bottom line is quite simple. Without completely parsing a perl script you can't match keywords reliably. The best source code you will find (in pure Perl), that probably does what you want is perltidy. Perltidy is reasonably robust and mature. It has syntax highlighting (if that was what you had in mind) available and obviously a reasonably robust parsing engine.
Just for laughs have a look at this code and pick the comments. Bonus points for a correct answer on snippet 2
print <<'drom"edary',<<"f#f",<<'=pod',<< ''; #comment Just another Perl Hacker drom"edary #foo f#f #bar =pod #foo #too #you # is there a comment in the snippet of code below or not??? Blame Abig +ail 0.0 BEGIN { if ($ARGV [0]) {eval 'sub foo () {print}'} else {eval 'sub foo ($) {print}'} } $_ = "Just another Perl Hacker\n"; foo /#/; 1;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|