@ARGV on WinNT

I've been using perl for a while on Unix and have just installed it on my WinNT machine.

How do I get the script to access parameters from the command line? For example, I want to type:

  popup.pl *.html

to run the script on all of the html files in the current directory.

Under Unix this is done with the @ARGV array, but I can't get it to work on WinNT, and I can't find anything in the documentation or FAQs about it.

thanks!
slugger
sluggerAsked:
Who is Participating?
 
b2piCommented:
Theres the problem.  You're telling perl to run the appropriate script (%1), but not to include the other args.

Change it to

pl_auto_file=D:\perl5\bin\perl.exe %1 %*

0
 
sluggerAuthor Commented:
Adjusted points to 25
0
 
b2piCommented:
For a complete explanation, take a look at the README.win32 file in the source directory of perl.  In any case, the problem isn't with perl, but with the shell (on Unix, the shell expands the *.html arg on the command line; simply put, NT doesn't).

To get around this, take another look at

perldoc -f glob

Then, for any argument (say, ARGV[0]) that contains wildcards, or even those that don't, just glob the argument.  Thus, to replace the NT ARGV with the basic unix equivalent:

my(@NARGV);
foreach (@ARGV) {
     push(@NARGV, glob);
}
@ARGV = @NARGV;


0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sluggerAuthor Commented:
Thanks for replying b2pi; unfortunately I wasn't clear enough in my question. I don't seem to be able to get any arguments at all into the script. For example, if this is my script popup.pl:

foreach $arg (@ARGV) {
      print $arg;
      }

and I type at the command line:

 popup.pl hello goodbye

I get nothing printed. Perhaps I wasn't clear, it's not just a 'glob' issue, it's getting any parameters at all into the script.

Once I get this part figured out I can probably 'glob' to my heart's content.

thanks
slugger
0
 
sluggerAuthor Commented:
My question is really not how to do a glob but how to pass a command line parameter into the script on Win/NT. If my script is popup.pl:

foreach $arg (@ARGV) {
      print $arg;
      print "\n";
      }

and I type at the command line:

       popup.pl hello goodbye

I get nothing printed. Perhaps I wasn't clear, it's not just a 'glob' issue, it's getting any parameters at all into
the script. The same script works fine on Unix.

thanks
ss
0
 
b2piCommented:
1.) Open up a command window.
2.) Give the command

> assoc .pl

(yes, there is a space between the c and the period)
It should return something like

> assoc .pl
pl=PerlScript

3.) Give the command

ftype perlscript

4.) What does that return?


0
 
sluggerAuthor Commented:
assoc .pl
pl=mks_perl

ftype perlscript
File type 'perlscript' not found or no open command associated with it.


0
 
b2piCommented:
(Actually, what I wanted in that last case was

ftype mks_perl


But are you really using mks_perl?  If so, download the latest source or binary distribution from www.perl.com and get with the modern world (I believe that mks is a 4.0)


0
 
sluggerAuthor Commented:
Actually I did download and install the latest perl 5.004_02. I don't know why it's calling mks_perl in this case; when I type "which perl" it is using the new one in my perl5 directory (I added it to the beginning of the path configuration).

At any rate:
ftype mks_perl
mks_perl=d:\perl5\bin\perl.exe %1

This is where my new perl5 installation is. (The mks version is in c:\mks52\mksnt\perl.exe, but I've disabled it.)

Perhaps I need to go into regedit and delete the .pl file type, and then re-type the .pl files?

thanks for all your help.
slugger

0
 
sluggerAuthor Commented:
Ok, I've deleted .pl from regedit and re-associated the .pl file type. I now get:

assoc .pl
pl=pl_auto_file

ftype pl_auto_file
pl_auto_file=D:\perl5\bin\perl.exe %1

slugger
0
 
sluggerAuthor Commented:
Adjusted points to 75
0
 
sluggerAuthor Commented:
That was it! thanks so much, who would've thought it was something so logical? :-)

(adding a few points since it was harder than I thought.)

slugger
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.