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



  • 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.