Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Perl <dir_with_wildcards>

by haukex (Abbot)
on Dec 14, 2017 at 07:54 UTC ( #1205509=note: print w/replies, xml ) Need Help??


in reply to Perl <dir_with_wildcards>

"Hidden" a bit further down under I/O Operators:

If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context.

This is implemented by glob and File::Glob. Note that glob has a few caveats one should be aware of: It does not list filenames beginning with a dot by default, and it splits its argument on whitespace, which may be important in case you are interpolating variables into the pattern - you can use File::Glob ':bsd_glob'; to alleviate the latter caveat. Your particular usage </home/*/data/*.txt> (or equivalently, glob('/home/*/data/*.txt')) should be fine though.

Replies are listed 'Best First'.
Re^2: Perl <dir_with_wildcards>
by RMGir (Prior) on Dec 14, 2017 at 14:21 UTC
    Huh, wow, that works...

    Considering how many times I've used <> in its more "normal" usages, I'm surprised I never stumbled on this via a typo :)

    And it's been that way since (at least) 5.8.8. That's as far back as the perldoc.perl.org site goes.


    Mike

      The globbing feature of the <> operator dates back at least as far as the Perl-5.5.* versions, as it appeared in some of my earliest Perl books (Learning Perl, 2nd Ed; Programming Perl, 2nd Ed). That takes us into the late 90's.


      Dave

        I'm pretty sure <> as glob has been around since pretty close to the beginning of time as far as perl is concerned. It was present in Perl 4.

        A quick look in the git log of the perl5 repository shows commentary about it from Jun 1988 in perl 2.0

      And after getting used to mixing readline and glob behavior inside <...> , you'll probably find it more irritating that glob is also used to generate recombinations of strings without reading the file system

      If non-empty braces are the only wildcard characters used in the glob, no filenames are matched, but potentially many strings are returned. For example, this produces nine strings, one for each pairing of fruits and colors:

      my @many = glob "{apple,tomato,cherry}={green,yellow,red}";

      Reason is, Perl started as shell° scripting on steroids, it had to compete with similar glob mechanisms there.

      (I'm using this feature often, but am still irritated)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

      °) well <{ba,k,c,}sh> scripting if you want ;)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1205509]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2018-07-19 02:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (399 votes). Check out past polls.

    Notices?