Solved

@ARGV on WinNT

Posted on 1998-10-29
12
349 Views
Last Modified: 2008-07-03
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
0
Comment
Question by:slugger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 

Author Comment

by:slugger
ID: 1205812
Adjusted points to 25
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1205813
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
 

Author Comment

by:slugger
ID: 1205814
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:slugger
ID: 1205815
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
 
LVL 5

Expert Comment

by:b2pi
ID: 1205816
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
 

Author Comment

by:slugger
ID: 1205817
assoc .pl
pl=mks_perl

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


0
 
LVL 5

Expert Comment

by:b2pi
ID: 1205818
(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
 

Author Comment

by:slugger
ID: 1205819
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
 

Author Comment

by:slugger
ID: 1205820
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
 
LVL 5

Accepted Solution

by:
b2pi earned 70 total points
ID: 1205821
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
 

Author Comment

by:slugger
ID: 1205822
Adjusted points to 75
0
 

Author Comment

by:slugger
ID: 1205823
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question