Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2021-10-27 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (95 votes). Check out past polls.

    Notices?