Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi haukex,

you're making a very valid point++. I sort of feel guilty here, since I must admit that I do recommend glob every now and then (though quite rarely), because it makes most things shorter and easier (especially, compared to opendir/readir, because it returns filenames with their relative paths, that's really nice), it does what I want in probably 95% of the cases. And I must further confess that, when I happen to recommend glob, I usually do not list the caveats (especially not the fourth one, which I know but would not even think of mentioning); if you write one short line to recommend to perhaps use glob for its ease in a given situation, you just can't really add four paragraphs to warn about possible issues in other situations.

To tell the truth, I usually hesitate a bit before recommending it, because of the issues that you listed, but I still think it is a very practical operator and I don't think it should be banned (at least not on *nix systems). I am happy that it removes directory entries starting with a dot (it saves me a grep with a regex), because that's exactly what I need most of the time. I also like that way it does pattern expansion to pick up the files that I'm looking for (saves another grep). Even if it's not used so often, the multi pattern expansion when there is a white space can really be handy. And I am especially happy that it returns filenames with paths, as this is very often what I want to have. These are quite significant advantages IMHO.

Yet, I also agree with the caveats you're mentioning. Should we then throw the baby out with the bath water? I'm not quite sure, but I would tend to think we shouldn't. But, clearly, it should be used only in well defined situations. Should we recommend it? Or stop recommending it? I don't know.


In reply to Re: To glob or not to glob by Laurent_R
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 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?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found