Skip to content

Commit

Permalink
glob: calculate $dirsep dynamically (#862)
Browse files Browse the repository at this point in the history
* Add a function to find an appropriate $dirsep value based on catfile()
* Now it won't be necessary to reconfigure $dirsep manually if the program is used on DOS/Windows
* No change of behaviour on my Linux system
* test1: perl glob 'a*' ---> current dir entries starting with 'a'
* test2: perl glob 'dir/*a*' entries in dir/ containing letter 'a'
  • Loading branch information
mknos authored Dec 6, 2024
1 parent 079abb7 commit 8f84db3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions bin/glob
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ When invoking B<glob> as a function from the C<FastGlob> module, There
are several module-local variables that can be set for alternate
environments, they are listed below with their (UNIX-ish) defaults.
$FastGlob::dirsep = '/'; # directory path separator
$FastGlob::rootpat = '\A\Z'; # root directory prefix pattern
$FastGlob::curdir = '.'; # name of current directory in dir
$FastGlob::parentdir = '..'; # name of parent directory in dir
$FastGlob::hidedotfiles = 1; # hide filenames starting with .
So for MS-DOS for example, you could set these to:
$FastGlob::dirsep = '\\'; # directory path separator
$FastGlob::rootpat = '[A-Z]:'; # <Drive letter><colon> pattern
$FastGlob::curdir = '.'; # name of current directory in dir
$FastGlob::parentdir = '..'; # name of parent directory in dir
Expand Down Expand Up @@ -178,19 +176,21 @@ plain alternation), and made callable as a standalone script.
=cut

use Exporter ();
use File::Spec;

use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

$VERSION = 1.2_05;
$VERSION = 1.2_06;
@ISA = qw(Exporter);
@EXPORT = qw(&glob);
@EXPORT_OK = qw(dirsep rootpat curdir parentidr hidedotfiles);
@EXPORT_OK = qw(dirsep rootpat curdir parentdir hidedotfiles);

# platform specifics

use vars qw($dirsep $rootpat $curdir $parentdir $hidedotfiles $nested);
use vars qw($verbose $matched @errors);

$dirsep = '/';
$dirsep = getdirsep();
$rootpat= '\A\Z';
$curdir = '.';
$parentdir = '..';
Expand Down Expand Up @@ -267,6 +267,12 @@ sub match_glob {
return sort(@res);
}

sub getdirsep {
my $sep = File::Spec->catfile('a', 'a');
$sep =~ s/a//g;
return $sep;
}

sub recurseglob {
my($dir, $dirname, @comps) = @_;
my(@res) = ();
Expand Down

0 comments on commit 8f84db3

Please sign in to comment.