It's not as complicated as it looks; it would be much easier to understand if COMPARE didn't use $L as an LoL reference, and %L as a hash.

The main part of the program builds up 2 LOL (lists of lists, see perldsc). @R contains lists where the 5th element isn't --, and @L contains those where the 5th element IS and 2nd element isn't.

Note that there's no error checking for cases where both the 2nd and 5th elements are --, I don't know if that matters to you.

The 2 LOL's are then passed into the COMPARE routine. By the way, the

use Data::Dumper;
looks like a red herring; I don't see anything there that needs that module.

In compare, $L and $R are references to the LOLs built up in the main routine. %L and %R are hashes that map all of the indexes in @$L and @$R respectively to (anything, since the key existence is all that matters), to keep a set of the rows that still need to be processed.

The nested for loops go over every possible combination of items in @$R and @$L, checking if the 4th element in the @$R entry matches the 2nd in @$L. In that case, and if that entry in @$L hasn't already been matched (that's the next unless part), those entries are deleted from %R and %L (so they don't get printed out later), and the "match" line is printed out. The "last;" call ends the $J loop, and moves processing on to the next item in @$R.

After the 2 loops, all the unmatched entries are printed out.

Is it clearer now, or did I make it worse? :)
--
Mike


In reply to Re: Enlightenment by RMGir
in thread Enlightenment by johnirl

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.