Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Syntactic Confectionery Delight

Comment on


I think you pretty much answered your own question: B::Deparse seems to do just what you want:

#! perl use Modern::Perl; my ($foo, $bar, $baz, $mul, $op1, $op2); my $cr1 = sub { $foo = $bar * $baz; }; my $cr2 = sub { $foo = $bar * $baz; # Note whitespace differences }; my $cr3 = sub { $mul = $op1 * $op2; }; my $cr4 = sub { $foo = $baz * $bar; }; compare_subs($cr1, $cr2); compare_subs($cr3, $cr4); sub compare_subs { my ($s1, $s2) = @_; use B::Deparse; my $deparse = B::Deparse->new("-p", "-sC"); my $body1 = $deparse->coderef2text($s1); my $body2 = $deparse->coderef2text($s2); if ($body1 eq $body2) { say 'Identical'; } else { say 'Different'; } }


21:39 >perl Identical Different 21:40 >

So, the initial results look promising, at least!

Hope that helps,


In reply to Re: Compare CODE by Athanasius
in thread Compare CODE by PetaMem

and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2014-03-15 17:20 GMT
    Find Nodes?
      Voting Booth?

      Have you used a cryptocurrency?

      Results (320 votes), past polls