Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-05-19 08:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (71 votes). Check out past polls.

    Notices?