FYI, I've long wondered at the purpose of Array::Diff and haven't found the documentation to be helpful on that point. But looking at it tonight I realized that the interface provided mostly doesn't make sense given the implementation.

The interface that Array::Diff provides seems to be one that would make sense for a much different implementation. It seems to be offering what looks like a "set difference". That is, the interface looks like one for when the order of the items in each array does not matter. And the documentation does nothing to counter that impression (unless you go read the documentation for Algorithm::Diff in enough detail).

I don't yet see any way to make use of the information that Array::Diff provides in general when order actually does matter, other than as some general, imprecise feedback that just gives a "feel" for how different the lists are or when all you care about is "is anything different?". I guess you could make use of the information if duplicates are not possible, though doing so would be awkward.

And the reviews of Array-Diff indicating that I'm not alone in being confused. One reviewer appears to think the purpose is just "are they different at all?". Others are surprised that order matters. If you just want "are they different" or if order doesn't matter, than you can determine such much more efficiently than how Algorithm::Diff works. If order does matter, then Array::Diff is replacing 6 lines of code. If you just want the count, then you can do that with one line of code.

Here is an example of what Array::Diff tells you:

@one = qw< a b c d >; @two = qw< d a c b >; # deleted: b d # added: d b

If that is the type of information you want for such a case, could you tell me how you actually make use of that information? I am genuinely curious.

- tye        


In reply to Re: Using Array::Diff (purpose?) by tye
in thread Using Array::Diff by edimusrex

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.