A global counter may or may not be the way to go here, depending on the context in which you want to do this. If this is for a small script that you need for system administration or so, I'd say yes, use a global counter. If it's part of a larger project, use a cleaner solution with hooks/callback functions.

Take a look at Dominus's book Higher-Order Perl, too, walking a directory tree is one of the examples he uses in the first chapter (pp. 16-25). You could probably adapt what he's doing there. (And all the code snippets from his book are online, e.g. dir-walk-cb-def and so on.)

Other than that, to actually print the right numbers -- for a file it's straightforward; for a directory, "processed" equals "discovered" plus twice the number of files in that directory, plus one, so just print that (without increasing the counter, of course).


In reply to Re: Help with node discovering and processing by AppleFritter
in thread Help with node discovering and processing by cspctec

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.