What's the best way to get all Perl's builtin-functions as a list?
I'm trying to update a xml-file for syntax-highlighting an开发者_如何学God therefor I was wondering what's the simplest way to get a list of all Perl built-in-functions.
Here is quick implementation of cnicutar's idea:
use Pod::Find qw(pod_where);
my $perlfunc_path = pod_where({ -inc => 1 }, 'perlfunc');
open my $in, "<", $perlfunc_path or die "$perlfunc_path: $!";
while(<$in>) {
last if /=head2 Alphabetical/;
}
while(<$in>) {
print "$1\n" if /=item (.{2,})/;
}
Gives you list including parameters like this:
-X FILEHANDLE
-X EXPR
-X DIRHANDLE
-X
abs VALUE
abs
...
Look at the toke.c file in the perl
source:
$ perl -nE 'next unless /case KEY_(\S+):/; say $1' toke.c | sort | uniq
You'll find many of the things that won't show up in perlfunc. However, that depends on how you want to segment that various things that you want to color.
You could also look at PPI, a static Perl parser, or the existing Perl syntax highlighters.
I would parse perldoc perlfunc
(the part "Perl Functions by Category").
I ran into the same issue just now, and
egrep '^=item' /usr/lib/perl5/5.10.0/pod/perlfunc.pod | perl -anle '$F[1]=~s/\W//g; print $F[1]' | sort | uniq
worked for me (but, be warned, it's not perfect)
精彩评论