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

Dear Friends:

I just came up with this question, when I used @ARGV in my program and if I feed the program input files like "*.txt", such as perl program.pl *.txt, will this program automatically take all the "*.txt" file in the current directory and feed them to @ARGV?

It seems doing so. But I cannot find reference for this behavior.

Thank you

Replies are listed 'Best First'.
Re: @ARGV and glob
by Corion (Patriarch) on Aug 22, 2017 at 15:49 UTC

    The expansion of wildcards on the command line has nothing to do with Perl. It is a feature of the shell you use.

    For example under Windows with the cmd.exe shell, no such automatic expansion of wildcards occurs.

      oh, I see. Which means the shell actually feeds perl program all the files with ".txt". Thank you for your clear answer.
Re: @ARGV and glob
by haukex (Archbishop) on Aug 22, 2017 at 16:23 UTC
    But I cannot find reference for this behavior.

    As Corion said, this is a feature of the shell. See for example "Filename Expansion" (and the following "Pattern Matching") in the Bash Reference Manual; of course there are lots of other shells, but the basic behavior of * and ? are pretty much the same almost everywhere.

    Under Windows, you can use Win32::Autoglob to emulate this behavior.

Re: @ARGV and glob
by ikegami (Patriarch) on Aug 22, 2017 at 18:59 UTC

    It depends on the shell to which that command is passed.

    cmd and PowerShell will pass *.txt

    sh, csh and their derivatives will expand the glob and pass multiple files names. (Their behaviour may vary when there are no matching file names. Some will pass *.txt.)

Re: @ARGV and glob
by thanos1983 (Parson) on Aug 22, 2017 at 16:11 UTC