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



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