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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|