Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: glob() and dot files (updated)

by perlancar (Hermit)
on Apr 13, 2020 at 09:46 UTC ( [id://11115439]=note: print w/replies, xml ) Need Help??


in reply to Re: glob() and dot files (updated)
in thread glob() and dot files

Hi haukex,

Thanks for pointing out about your glob() post. I think I read it in the past. If wildcard is problematic, this gives me an idea of creating a glob-like function but with regex instead: re_glob('.*') or re_glob(qr/\.foo/). It will not skip dotfiles by default.

By the way, most of the time for practical reasons I don't bother with File::Spec at all, because why would I sacrifice myself using catfile() and no_upwards when I will not be using path separator other than "/", and parent directory other than ".." (probably for the rest of my life).

Replies are listed 'Best First'.
Re^3: glob() and dot files
by haukex (Archbishop) on Apr 13, 2020 at 09:59 UTC
    By the way, most of the time for practical reasons I don't bother with File::Spec at all, because why would I sacrifice myself using catfile() and no_upwards when I will not be using path separator other than "/", and parent directory other than ".." (probably for the rest of my life).

    Well, if you know your scripts are only ever going to be run on *NIX, then sure. But what you're sacrificing is portability. For example, even nowadays, there are some Windows programs that can't handle / path separators and require \. Personally, although I've written code like "$path/$file" myself, I usually like my code to be as portable as possible, and if you're considering writing a re_glob(qr/\.foo/) function, you might want to release it as a module*, and then portability becomes important, IMHO.

    * use Path::Tiny; my @files = path($path)->children(qr/\.foo/); But sadly, Path::Tiny "does not try to work for anything except Unix-like and Win32 platforms." Alternative: use Path::Class; my @files = grep {$_->basename=~/\.foo/} dir(".")->children;

      For example, even nowadays, there are some Windows programs that can't handle / path separators and require \.
      I don't remember why I wanted to call explorer.exe from Perl, but I did, and found out it understands pathes only with backslashes...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found