You might want to give Perl::Compare a look.

UPDATE

Actually it seems that Perl::Compare might not be in the best state right now (it seems he is working on updating it to the latest PPI version). A simplistic replacement is using the normalized method of the PPI::Document object and then comparing the results (the results are actually PPI::Document::Normalized objects which have their == operators overloaded). Here is some code:

use strict; use warnings; use PPI::Document; my $d1 = PPI::Document->new('$x++'); my $d2 = PPI::Document->new('$x += 1'); my $d3 = PPI::Document->new('$x = x + 1'); print((($d1->normalized() == $d2->normalized) && ($d2->normalized() == $d3->normalized) && ($d3->normalized() == $d1->normalized)) ? "they are all equivalent\n" : "they are not equvalient\n"); print(($d1->normalized() == $d2->normalized) ? "1 and 2 are equivalent\n" : "1 and 2 are not equvalient\n"); print(($d2->normalized() == $d3->normalized) ? "2 and 3 are equivalent\n" : "2 and 3 are not equvalient\n"); print(($d3->normalized() == $d1->normalized) ? "3 and 1 are equivalent\n" : "3 and 1 are not equvalient\n");
And the output:
they are not equvalient 1 and 2 are not equvalient 2 and 3 are not equvalient 3 and 1 are not equvalient

-stvn

In reply to Re: Equivalency of Code by stvn
in thread Equivalency of Code by rkosai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.