One of my complaints about File::Find is that its silly optimization (which has caused me tons of grief over the years because it was being used in so many places where it just plain breaks) of checking the nlinks from stat (in hopes of deciding that there are no subdirectories) means that you can't assume that it has just done a stat or lstat on the file in question so you have to restat the file by name and not use the magic _ as you have done above.

So you either need to prepend a $ to your first _ or you need to do something to ensure that File::Find doesn't use the silly nlinks optimization:

$File::Find::dont_use_nlink = 1;
Note that if you don't disable the silly nlinks optimization, then you'll have to change that _ to $_ (or risk your script breaking in some directories on some systems) and so your script will run slower which just makes me laugh since File::Find's documentation says:
If you do set $File::Find::dont_use_nlink to 1, you will notice slow-downs.
I particularly like the "notice" part. Yeah, sure I will. (:

More than once I've tried to make the nlinks optimization something that you have to request be done for you but the emotional attachment to it for some at p5p is just too great. It looks like several improvements to the code have been made regarding this feature so it is less likely to be used when it shouldn't (other than slowing down most correct uses of File::Find). I'm not convinced that it is perfect, however, because I'm pretty sure I've run into file systems where nlinks on directories are not either always 1 or always 2+number_of_subdirectories. So now I'm mostly amused with how the emotional attachment to this has manifested itself in the module documentation.

Oh well, I don't use File::Find much anymore. For trivial uses, it is usually easier to use /bin/find and for non-trivial uses it is usually easier to roll my own directory traverser than try to figure out how to use awkward call-backs to get done what I want.

                - tye

In reply to Re^2: system command error ($_ not _) by tye
in thread system command error by Jassica

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.