Inside your process subroutine you do not chance directories to the current directory you're reading nor do you use the full path of the file. Instead calling process on $_. Which begs the question why doesn't your script raise an error? It seems calling -d on the file is insufficient. I think it would be wise to test whether the file you are passing to process actually exists.

One of the reasons for not catching this bug is that you have two nearly identical pieces of code. One in your main routine and the other your process subroutine. In this case you correctly called -d on the full path in you main code but not in your subroutine. It is errors like these why programmers eschew duplication. You have the process subroutine just call it initially instead of having a separate loop in you main code.

Addendum: Your code seems to be confused about whether to use absolute or relative paths. You need to either:

  • Use relative paths; pushing the current path on a stack before calling process(), where you cd to the directory in question, then popping the saved directory upon return.
  • Use absolute paths where every call uses the full pathname. Process() being called with the full pathname and having to append the current directory to the pathname before calling itself.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}

    In reply to Re: Count folder/files in directory by starbolin
    in thread Count folder/files in directory by Anonymous Monk

    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.