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

Hello, Could someone resolve the puzzle for me: I have the directory of perl.exe set as in the path environment variable in Windows2000. I write a perl script and have it is directory in the path as well. I have set it that the way to open this file is thru perl.exe. So now when I type it as a command, it should automatically use perl to execute it, right? But this file takes an argument. When I use the form like: foo.pl inputFile It does not take any argument at all. The scalar(@ARGV) is 0. I used active perl. Has anyone encountered this situation before? Could you please let me know what happened? Thank you ginger

Replies are listed 'Best First'.
Re: $ARGV for a perl script
by BrowserUk (Patriarch) on Sep 16, 2002 at 22:54 UTC

    I assume that by

    I have set it that the way to open this file is thru perl.exe
    you are using the assoc and ftype comands to achieve this.

    I think that what you have forgotten to do is allow for arguments to the script in the ftypedefinition.

    On my box (NT) these are set up as follows:

    C:\test>assoc .pl .pl=perl_script C:\test>ftype perl_script perl_script=e:\perl\bin\perl.exe -sw %1 %* C:\test>

    The -sw allows for command line switches to the script to be parsed and automatically enables warning in all perl script invoked this way. (See perlrun).

    The %1 is the name of the file being run, and the bit that I think you have forgotton, the %* ensures that the shell passes on any command line args after the script name .

    Hope this helps.


    Well It's better than the Abottoire, but Yorkshire!
Re: $ARGV for a perl script
by chromatic (Archbishop) on Sep 16, 2002 at 22:48 UTC

    A guess: you have an alias called 'perl' that invokes perl.exe on the first argument. Unforunately, you don't pass any other arguments. I'd expect to see something like this (though it's untested):

    /path/to/perl.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

    (Disclaimer: that looks inelegant even to me, and I'm not a great Windows programmer.)

Re: $ARGV for a perl script
by blm (Hermit) on Sep 16, 2002 at 22:56 UTC

    Did you have to set manually the "way to open this file is thru perl.exe? I didn't! And I don't have the same problem luckily. On this Windows 2000 box the extension .pl is associated to C:\Perl\bin\Perl.exe "%1" %* where %* would be equivalent to all the arguments passed initially on the command-line to the script. So %* == %2 %3 %4 %5 etc