G - command line parameter globing

version 3.2


 Apart from "use G;" on top of your script or adding -MG to PERL5OPT there's
 nothing you have to do. The module will take the command line and parse it as
 the God intended. Taking into account both double and single quotes
 (not entirely, but close to the Unix way) and even backticks.
 This module does nothing at all under anything but $^O eq MSWin32.


This module was made for use on Windoze systems, where the shell doesn't do parameter globing. Once you add -MG to PERL5OPT variable you do not have to care about it ;-) (Well almost :-(


You may either use the module explicitly in the calls to perl:

 c:\> perl -MG *.txt

or use it in perl script:
 use G;

or add the -MG to PERL5OPT system variable. After this the module will be used in all perl scripts.

The module of course makes sure the globing is not done several times.

Since it processes (since version 3.0) the plain command line, not the list broken (in both meanings) by C runtime it understands single quotes and backticks as well.

  perl -MG -e "print join(qq{\n}, @ARGV)" *.txt
  perl -MG -e "print join(qq{\n}, @ARGV)" '*.txt'
  perl -MG -e "print join(qq{\n}, @ARGV)" 'hello world'
  perl -MG -e "print join(qq{\n}, @ARGV)" 'hello   world'

The number of spaces will be preserved !

You may even use the backslash escapes in doublequoted or unquoted parameters, but since windoze use backslash as the directory separator, the module does the escape interpolation only if you begin the parameter by ':'.

  perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" "hello \n world"
  perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" ":hello \n world"

The only characters that will be escaped in other unquoted or doublequoted strings are doublequotes, wildchars (* and ?) and backslashes :

  perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" "I said: \"How are you\?\""

in single quoted it's only the single quotes and backslashes

  perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" 'Hi d\'Artagnan'

backslashes folowed by other characters are preserved!

The other cool feature is the backticks:

 perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" `dir c:\\`

Please note that you have to double the backslash before the closing backtick !

Please note also that

 perl -MG -e "print '<',join(qq{>\n<}, @ARGV),'>'" "hello"'world'

will give you TWO arguments, not one !

Enjoy ;-)


Bill Odom (