<?xml version="1.0" encoding="windows-1252"?>
<node id="1008270" title="Compare CODE" created="2012-12-11 06:22:42" updated="2012-12-11 06:22:42">
<type id="115">
perlquestion</type>
<author id="89299">
PetaMem</author>
<data>
<field name="doctext">
&lt;p&gt;Hi!&lt;/p&gt;

&lt;p&gt;Given two coderefs. Is there an (elegant) way to compare the code they're pointing to?&lt;/p&gt;

&lt;p&gt;No, I don't need any fancy stuff like solving the halting problem. ;-) I do not even need to know if the code is equivalent. It would be completely sufficient if these&lt;/p&gt;

&lt;code&gt;

my $cr1 = sub {
 $foo = $bar * $baz;
}

my $cr2 = sub {
 $foo = $bar * $baz;
}

&lt;/code&gt;

&lt;p&gt;Would be considered "same". Ideally with the whitespaces being irrelevant. All mutations, invariants etc. can safely be considered 'different'. i.e.&lt;/p&gt;

&lt;code&gt;
my $cr3 = sub {
 $mul = $op1 * $op2;
}

my $cr4 = sub {
 $foo = $baz * $bar;
}
&lt;/code&gt;

&lt;p&gt;To sum up: It would be sufficient to have a function that - for two given coderefs (pointing to different addresses) - would just return "identic" if they'd be the same list of opcodes.&lt;/p&gt;

&lt;p&gt;Howto? B:: something?&lt;/p&gt;

&lt;p&gt;Thank you for your guidance.&lt;/p&gt;


&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-89299"&gt;
&lt;p&gt;&lt;font size=-1&gt;Bye&lt;br&gt;
&amp;nbsp;PetaMem&lt;/font&gt; &amp;nbsp; &lt;font size=-2&gt; &amp;nbsp; All Perl: &amp;nbsp; &lt;a href="http://www.petamem.com"&gt;MT, NLP, NLU&lt;/a&gt;&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
