I hesitated quite a while before sharing this, but it seems that it can only be improved. (And I did write it some time ago.)
I hacked up File::DosGlob to suit me a while back. I vaguely recall some problem with globs that didn't match anything, and whether they were silently dropped, or passed through as a glob. Either or both of these may cause needless errors or incomplete data, so I added options and checking for the caller to control this behavior, and was rather paranoid about accepting options that weren't recognized.
I should go back and clean this up nice with POD, etc., but I'm lazy.
I also had unsophisticated users running my scripts, and sometimes running them on *nix. They would not need this module, and wouldn't have installed it, but of course it couldn't just be used, so I used this code instead:
# This BEGIN block avoids including File::DosGlob::Param for non-windo
+ws systems
BEGIN
{
if ( $^O =~ /win/i )
{
require File::DosGlob::Param;
import File::DosGlob::Param qw( dosglob );
}
}
Now, this didn't avoid the issue of the user not having it installed on Windows, but at least it didn't blow up unnecessarily in *nix.
And finally, an example invocation:
# convert filename wildcards to actual filenames
if ( $^O =~ /win/i ) # only if DOS
{
if ( exists( $INC{'File/DosGlob/Param.pm'} ) ) # only if loaded
{
dosglob( "Array_Ref" => \@ARGV,
"Remove_Empty_Matches" => 1,
"Warn_On_Empty_Matches" => 1 );
}
END
{
if ( ( $^O =~ /win/i )
and not exists( $INC{'File/DosGlob/Param.pm'} ) )
{
warn "Consider installing module File::DosGlob::Param...\n
+";
}
}
}
-QM
--
Quantum Mechanics: The dreams stuff is made of
|