Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: To glob or not to glob

by haukex (Bishop)
on Jan 11, 2018 at 12:09 UTC ( #1207115=note: print w/replies, xml ) Need Help??

in reply to Re: To glob or not to glob
in thread To glob or not to glob

Thank you for the reply!

Using it the way you describe will cause porting issues for older perl versions

You are correct that the :bsd_glob export tag wasn't added until Perl v5.16, sometime from File::Glob 1.13 to 1.17 in File::Glob 1.15. (Note you've got a typo in your example, -MFile::Glob::bsd_glob. fixed) But from the File::Glob docs:

The :glob tag, now discouraged, is the old version of :bsd_glob. It exports the same constants and functions, but its glob() override does not support iteration; it returns the last file name in scalar context.

So one backwards-compatible way to go is use File::Glob ':glob';, unless you want to use it in scalar context, which might not be a good idea anyway due to the issue choroba described.

$ touch 'foo bar.txt' $ perl -MFile::Glob=:glob -e 'print for <*foo bar*>'

This works in Perl 5.6.2 thru 5.24, and warns about the deprecation of :glob in 5.26. What you can do in Perl v5.6 thru v5.26 (and hopefully beyond) is either

use File::Glob 'bsd_glob'; print for bsd_glob('*foo bar*'); # -- or -- use File::Glob $] lt '5.016' ? ':glob' : ':bsd_glob'; print for <*foo bar*>;

With the limitation of not being able to use the latter in scalar context until Perl v5.16 and up (Update: and the former not at all, unfortunately).

Does this in your opinion imply that File::Glob should be dual-lived?

No, I don't yet have a well-formed opinion either way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-05-24 09:55 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (82 votes). Check out past polls.