Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Perl <dir_with_wildcards>

by haukex (Archbishop)
on Dec 14, 2017 at 07:54 UTC ( [id://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
      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 ;)

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2024-04-19 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found