Yes, grep{!$seen{$_}++} just removes duplicates from the list. Perl grep is filtering operation and more powerful than command line grep. It passes the input to the output if the last line of the grep evaluates to "true".

This grep code checks the "truthness" of the seen hash entry for $_. The ! makes it a "not". So this is true if we have not seen a value before. The ++ is a post increment which happens after we've tested for existence. If the key does not already exist, Perl creates it, and allows the undef initial value to be used in the increment. The resulting value is 1 (0+1). If the key already exists it just gets incremented.

The list returned from priorFiles is every possible file that could have affected a particular output file. It contains dupes because some of the input files will share a at least a partial ancestry. priorFiles() is a bit tricky as it calls itself. This is a recursive function and may a bit mind-bending if you haven't seen one before.

I think you are on the way now. Play with the code, insert prints to watch what it does.


In reply to Re^5: Parsing a file and finding the dependencies in it by Marshall
in thread Parsing a file and finding the dependencies in it by legendx

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.