Thank you all very much for the replies so far! (I've /msg'ed everyone to make you aware of this reply-to-all.)

Laurent_R, Eily, and morgon, thank you for your thoughts on recommending glob. I'm not sure if there is one true answer as to whether glob can generally be recommended or not - when used properly, it provides nice and short code, while on the other hand, the various caveats can be easily forgotten, and later refactoring of the code could introduce problems, e.g. when a formerly static pattern gets a variable interpolated into it. I guess my emphasis should have been a bit more strong: "it should not be blindly used or recommended."

I would probably say that glob with fixed strings is generally fine, but interpolating variables (especially user-supplied paths at the beginning of the pattern) can get very tricky, and I personally often reach for Path::Class in these cases. Another situation in which glob is probably fine is when the user supplies the entire pattern, e.g. as part of a configuration file ("files = ~/foo/*.log"), and one then does @files = glob($config{files}). One can simply point to the documentation of glob and File::Glob when documenting that configuration option. (The problem of someone overriding glob globally remains, although I wonder how often that might happen...)

choroba, thank you for the additional caveat, which I've added to the root node. Now that you mention it, I dimly remember this being discussed before, and a bit of super searching found this thread with the reference to RT#123404 - I should have remembered this!

karlgoethebier, you are quite correct that those modules can also be limited to just one directory, thank you. It feels like a little bit of overkill to use a module like those for a single directory, but then again, it's good to use the tools one knows. My comment was hinting at the fact that I've seen modules like File::Find etc. recommended as an alternative to readdir without mentioning their recursive behavior.


In reply to Re: To glob or not to glob by haukex
in thread To glob or not to glob by haukex

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.