Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: To glob or not to glob

by Laurent_R (Canon)
on Jan 07, 2018 at 22:21 UTC ( #1206865=note: print w/replies, xml ) Need Help??


in reply to To glob or not to glob

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206865]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2022-05-26 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (94 votes). Check out past polls.

    Notices?