Core module File::DosGlob provides the tools to expand wildcards in the manner a Windows user would expect, so it's just a question to use the glob
provided by this module as follows:
use File::DosGlob qw( glob );
@ARGV = map glob, @ARGV;
Note that doing this using the builtin glob
would break paths that contain spaces, a relatively common occurrence on Windows. It would also mishandle *.*
, which is expected to return all files.
Note that it's best to expand the patterns after processing command-line options to avoid risking expanding the pattern into a command-line option.
use File::DosGlob qw( glob );
use Getopt::Long qw( GetOptions );
GetOptions(...)
or die_usage();
@ARGV = map glob, @ARGV;
For a one-liner, you could use the following:
perl -MFile::DosGlob=glob -ne"BEGIN { @ARGV = map glob, @ARGV } ..." ...
The BEGIN
ensures the code is run before the input-reading loop created by -n
starts.