Perl, Wildcards and the Windows Command Line
When developing for multiple platforms, its always the little things that catch you out.
Heres one example I found while developing gcal, a Command Line Interface to Google Calendar. On Unix (including Mac OS X shells) wildcard expansion is done by the shell, and then the expanded list of files is passed on to the program being run. On Windows, the shell doesn’t do any expansion, and it’s up to programs to do the expansion1.
To get around this in Perl, you can do something like this2.
my @args = ($^O eq 'MSWin32') ? map { glob } @ARGV : @ARGV;
Here we are passing all the arguments to glob, which will do the shell expansions, including wildcards. We only want to do this for Windows, as if you use it on Unix you risk globbing real file names - asterisks and question marks are valid characters in Unix file names.