If you need to extract the exact source code, it may be quite difficult. If it is sufficient to get a functional equivalent, look into B::Deparse; from the docs:
and here's a specific example as a one-liner:use B::Deparse; $deparse = B::Deparse->new("-p", "-sC"); $body = $deparse->coderef2text(\&func);
zen% perl -MB::Deparse -MCarp -wle 'print B::Deparse->new("-p","-sC" +)->coderef2text(\&Carp::confess)' { package Carp; die(longmess(@_)); } zen%
See the rest of the docs for full details of the options available.
Hugo
In reply to Re: Extract subroutines from a Perl script. OR: "Only perl can parse Perl." But can it help me to do so?
by hv
in thread Extract subroutines from a Perl script. OR: "Only perl can parse Perl." But can it help me to do so?
by muba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |