You said that you want to work on subfolders. The
next if -f $_;
checks if the current directory entry (contained in $_) is a regular file (as opposed to directories or folders in MS parlance), and, if it is, goes directly to the next directory entry in the list. This way, the script will only work on subdirectories.

Update: as correctly pointed out below by Happy-the-monk, the code above will filter out only plain files (I used the words "regular files" to mean that). So that it is not completely accurate to write, as I did above, that the script will only work on subdirectories, since there can be other entities than just plain files and subdirectories. And it would be better to identify real directories with something like next unless -d $_;. Thank you, Happy-the-monk, for the added accuracy.

Je suis Charlie.

In reply to Re^3: How to get sub-folder names using perl? by Laurent_R
in thread How to get sub-folder names using perl? by erhan

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.