Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

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

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.


In reply to Re^2: 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 surveying the Monastery: (3)
As of 2022-05-25 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (91 votes). Check out past polls.

    Notices?