CARVIEW |
Select Language
HTTP/2 200
cache-control: max-age=43200
server: Combust/Plack (Perl)
vary: Accept-Encoding
content-encoding: gzip
content-length: 1962
content-type: text/html; charset=utf-8
last-modified: Sun, 12 Oct 2025 05:34:16 GMT
traceparent: e1bd996f991fb05dd2860b71e9c38207
strict-transport-security: max-age=15768000
[PATCH] Enable File::DosGlob to handle arbitray glob patterns - nntp.perl.org
Front page | perl.perl5.porters |
Postings from July 2008
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About

[PATCH] Enable File::DosGlob to handle arbitray glob patterns
From:
alex.daviesDate:
July 27, 2008 10:39Subject:
[PATCH] Enable File::DosGlob to handle arbitray glob patternsMessage ID:
8359169A932A4EB99BE51505C8530D41@AmelieHere's a patch that simplifies passing arbitrary glob patterns to C< File::DosGlob::glob() > by making it accept an array reference containing the glob patterns. Rationale - if you want to DosGlob a path containing both spaces and backslashes eg. C:\Program Files\* You need to 'escape' it such that it passes thro' C<Text::ParseWords::parse_line()> in one piece. I currently use this to cover globbing arbitrary paths: sub dosglob { require File::DosGlob; my $pat = $_[0]; # just handle one pattern if ($pat =~ /[ ']/) { # escape it such that Text::ParseWords::parse_line() # sees unquoted text $pat =~ s|\\|\\\\|g; $pat =~ s|([ '])|\\$1|g; } return File::DosGlob::glob($pat); }; ..but it seems like overkill. My proposed change would allow you to simply say: File::DosGlob::glob \@glob_patterns File::DosGlob::glob ["C:\\Program Files\\*"] Cheers, alex. # %< --- DosGlob.pm-orig 2008-07-27 17:01:27.140625000 +0100 +++ DosGlob.pm-new 2008-07-27 17:13:36.593750000 +0100 @@ -9,7 +9,7 @@ package File::DosGlob; -our $VERSION = '1.01'; +our $VERSION = '1.02'; use strict; use warnings; @@ -313,7 +313,10 @@ $pat = $_ unless defined $pat; # extract patterns - if ($pat =~ /\s/) { + if (ref($pat) eq 'ARRAY') { + @pat = @$pat; + } + elsif ($pat =~ /\s/) { require Text::ParseWords; @pat = Text::ParseWords::parse_line('\s+',0,$pat); } @@ -434,6 +437,9 @@ @perlfiles = glob "..\\pe?l/*.p?"; print <..\\pe?l/*.p?>; + # to glob arbitrary pathnames, pass an array ref: + @matches = glob ["C:\\Program Files\\*\\*"]; + # from the command line (overrides only in main::) > perl -MFile::DosGlob=glob -e "print <../pe*/*p?>" @@ -460,6 +466,10 @@ C<Text::ParseWords::parse_line()>, so see L<Text::ParseWords> for details of the quoting rules used. +From version 1.02 onwards, C<File::DosGlob::glob()> also accepts an array +reference containing the glob patterns. This allows you to pass arbitrary +patterns which might contain both spaces and backslashes. + Extending it to csh patterns is left as an exercise to the reader. =head1 NOTES
- [PATCH] Enable File::DosGlob to handle arbitray glob patterns by alex.davies
nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About