sacco has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

After running a glob of files with a specific naming convention, I found I got undesirable results. I'm running on a Win32 platform.
example:
use File::DosGlob 'glob'; @files_to_pull = glob("???4000?.*"); foreach $file(@files_to_pull){ print "\n$file"; }
actual results:
4000A.01
XXX40002.123
YYY40003.123
EEE4000.111
ZZZ40003.224

expecting results:
XXX40002.123
YYY40003.123
ZZZ40003.224

Any suggestions?

Sacco

Replies are listed 'Best First'.
Re: glob wildcard chars (Dos)
by tye (Sage) on Sep 02, 2004 at 21:50 UTC

    That is how DosGlob is defined to work. If you don't like it, then use one of the several other File::*Glob modules instead (or just Perl's regular glob).

    - tye        

Re: glob wildcard chars
by ambrus (Abbot) on Sep 02, 2004 at 20:21 UTC

    I am surprised that 4000A.01 matches the patter. Anyway, if you want to fine-tune what names match your pattern, you could try using readdir instead of glob, like (untested):

    @files_to_pull = grep /\A...4000.\./, do { opendir my $dir, "."; readd +ir $dir; }; print "\n$_" for @files_to_pull;
Re: glob wildcard chars
by ikegami (Patriarch) on Sep 02, 2004 at 20:25 UTC

    I've never used globs, so I don't know if there's a way of making them work. Therefore, I'll suggest an alternative. You could always use DirHandle + regexp:

    use DirHandle (); $dh = DirHandle->new('.') or die("oh poo!\n"); while (defined($file = $dh->read()) { # Next line not needed here, but usually is. #next if ($file =~ /^\.\.?$/); next unless ($file =~ /^...4000.\./); print("\n$file"); } $dh->close();

    On second thought, this returns long files names, and I'm guessing your glob returns short file names? Ah well, it's already typed, so I'll post it in case it helps someone.