Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Extract subroutines from a Perl script. OR: "Only perl can parse Perl." But can it help me to do so?

by hv (Parson)
on Sep 24, 2004 at 10:57 UTC ( #393448=note: print w/ replies, xml ) Need Help??


in reply to Extract subroutines from a Perl script. OR: "Only perl can parse Perl." But can it help me to do so?

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:

use B::Deparse; $deparse = B::Deparse->new("-p", "-sC"); $body = $deparse->coderef2text(\&func);
and here's a specific example as a one-liner:
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


Comment on Re: Extract subroutines from a Perl script. OR: "Only perl can parse Perl." But can it help me to do so?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2014-11-28 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls