in reply to Re: Fix wildcard arguments under MSWin
in thread Fix wildcard arguments under MSWin

Since there's no harm in globbing names that lack wildcards, you can skip that check. And since glob looks to $_ if missing explicitly passed parameters, you can shorten this all to
@ARGV = map glob, @ARGV;

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: Fix wildcard arguments under MSWin
by gwadej (Chaplain) on Jul 28, 2003 at 12:09 UTC

    That's true.

    The test was actually there on purpose. I had scripts that I ran under MS and Unix. With the test I reduced the number of calls to glob when the command line was expanded properly. This made a significant difference in some of my code.

    I originally had an OS check in there, that I dropped when I started typing this into code. I then used the ternary test to correct for slow reactions on some Unix.

    Probably in the usual case this would be better. It's certainly easier to remember.

      You should probably instead check whether you're under Unix, and if so, not attempt to fix wildcard arguments at all. Unlike under Windows derivatives, wildcard characters are valid parts of a filename in Unix, and actual wildcards are usually already expanded by the shell. If you get a filename with what appears to be a wildcard in it, you're probably not meant to expand it.

      Makeshifts last the longest.

        The original of the code had a check for Windows and for the version of the ActiveState Perl that first stopped cleaning up for MS. I had put it in a module and it looked like this.

        @main::ARGV = map { /[\*\?]/ ? (glob $_) : ($_) } @main::ARGV if $^O =~ /Win/ && $] > 5.00307;

        Over time, this was reduced to the code I originally posted. (Which has now been reduced again.) The funny part is that all of the coditional logic was meant to make it easier to use as a module, so that you did not need to remember the code for the one-liner.

        Now, the current version is so small that it's easier to type it in when you need it than keep up with the module and always include it. (Since I usually use it in quicky scripts.) In production code, my command line processing is usually more complete than this.

        My original reason for posting the code was to help people who have been bitten by this under Windows. It was one little tool that I have used in the past to help people that had to work under MS Windows and would benefit from Perl.

        Thanks to everyone for helping me simplify this code even further.

        G. Wade