<?xml version="1.0" encoding="windows-1252"?>
<node id="393448" title="Re: Extract subroutines from a Perl script. OR: &quot;Only perl can parse Perl.&quot; But can it help me to do so?" created="2004-09-24 06:57:51" updated="2004-09-29 19:17:40">
<type id="11">
note</type>
<author id="209409">
hv</author>
<data>
<field name="doctext">
&lt;p&gt;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 [cpan://B::Deparse]; from the docs:&lt;code&gt;
  use B::Deparse;
  $deparse = B::Deparse-&gt;new("-p", "-sC");
  $body = $deparse-&gt;coderef2text(\&amp;func);
&lt;/code&gt;and here's a specific example as a one-liner:&lt;code&gt;
  zen% perl -MB::Deparse -MCarp -wle 'print B::Deparse-&gt;new("-p","-sC")-&gt;coderef2text(\&amp;Carp::confess)'
  {
      package Carp;
      die(longmess(@_));
  }
  zen% 
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;See the rest of the docs for full details of the options available.&lt;/p&gt;

&lt;p&gt;Hugo&lt;/p&gt;</field>
<field name="root_node">
393419</field>
<field name="parent_node">
393419</field>
</data>
</node>
