Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 and therefor I was wondering what's the simplest way to get a list of all Perl built-in-functions.

like image 262
sid_com Avatar asked Jul 17 '11 09:07

sid_com


3 Answers

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
...
like image 52
bvr Avatar answered Nov 14 '22 19:11

bvr


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.

like image 25
brian d foy Avatar answered Nov 14 '22 19:11

brian d foy


I would parse perldoc perlfunc (the part "Perl Functions by Category").

like image 26
cnicutar Avatar answered Nov 14 '22 19:11

cnicutar