develooper Front page | perl.perl5.porters | Postings from August 2001

Re: On "Command-line Wildcard Expansion"

Thread Previous | Thread Next
Tye McQueen
August 6, 2001 21:17
Re: On "Command-line Wildcard Expansion"
Message ID:
Excerpts from the mail message of Jenda Krynicky:
) > Delmonta / IIJIMA Hiromitsu wrote:
) > > 
) > >         (2) This DOES NOT expand expressions like "a:*.txt" and
) > >             you need to write "a:.\*.txt" instead (as of ActivePerl
) > >             Build #517 --- too old, yeh?).
) can do better ;-)

All I want is something that ships with Perl.  Actually, I
find the arguments for not rolling this into Perl itself very
unconvincing.  I'd prefer @ARGV to have wildcards expanded
in the name of portability and provide Win32::GetCommandLine()
for people who want to write Win32ish command-line interfaces.

Perl already has a built-in glob(), so the arguments against
Perl doing the glob()ing don't apply anymore.  Sure, don't
use the C RTL command-line globber for the reasons listed.
But, please, let's ease the confusion of those new to Perl
under Win32 who just want some simple script to work.

) > This should be sufficient (at least it works for me):
) > 
) > use File::DosGlob;
) > @ARGV = map { File::DosGlob::glob $_ } @ARGV;

You don't need to use File::DosGlob anymore, BTW.

) ... if you want all parameters to be treated as file masks.

That is a bit misleading.  glob("foo-^&#@") is "foo-^&#@"
(at least under Win32).  And if Perl were to have built-in
command-line glob()ing for Win32, I'd want an argument of
"*.x" to remain "*.x" in the absense of any matching files.
The only problem I see with the above code is that it
_silently_ drops "*.x" from the command line.

For quick hacks I use:

BEGIN { @ARGV= map glob($_) || $_, @ARGV if $^O =~ /MSWin32/i }

realizing that wildcards that match only a single file that is
named "0" will appear to fail.  If that bothers you, another
not-as-quick hack is:

    my @m;
    @ARGV= map { ( @m= glob($_) ) ? @m : $_ } @ARGV
	if $^O =~ /MSWin32/i;


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About