Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: glob() and dot files

by haukex (Archbishop)
on Apr 13, 2020 at 09:59 UTC ( [id://11115441] : note . print w/replies, xml ) Need Help??


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

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;

Replies are listed 'Best First'.
Re^4: glob() and dot files
by soonix (Canon) on Apr 13, 2020 at 11:28 UTC
    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...