WithABeard has asked for the wisdom of the Perl Monks concerning the following question:

It seems that perl doesn't glob arguments on windows.

Output in windows command prompt:

c:\scratch>dir /B file1 file2 file3 c:\scratch>perl -wnl -e "BEGIN{ print qq(Arguments: @ARGV); exit; }" * Arguments: * c:\scratch>|

compared to output in a linux shell:

Linux > ls file1 file2 file3 Linux > perl -wnl -e 'BEGIN { print "Arguments: @ARGV"; exit; }' * Arguments: file1 file2 file3 Linux > |

A little annoying when I want to use my scripts on both linux and windows.

I solved it with a tiny module in my home directory:

package Glob::Auto; use strict; BEGIN { @ARGV or return; # done if no arguments @ARGV = map { -e ? $_ : glob $_ } @ARGV; # glob anything that d +oesn't exist } 1;

So I simply add use Glob::Auto; to my script, and it works the same on windows as on linux.

Has anyone experienced the same? Any other solutions?

Could it be a bug? I am using Strawberry Perl version 5.32

Replies are listed 'Best First'.
Re: globbing arguments on windows
by haukex (Archbishop) on Jan 16, 2023 at 12:12 UTC

      that's perfect. thanks!

        Hello WithABeard

        > of course there is..

        ..or you can build a totally unuseful perl distro to do the same :)

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: globbing arguments on windows
by hv (Prior) on Jan 16, 2023 at 11:27 UTC

    That is not perl globbing the arguments, but your linux shell. You can see this if you run echo *.

Re: globbing arguments on windows
by WithABeard (Beadle) on Jan 16, 2023 at 11:28 UTC