ARGV[] unable to pick up command line arguments

N

Niall Macpherson

I've recently returned to using perl after a year or so away.

I inherited a script which was using Getopt::Std but when I ran it I
couldn't seem to pick up the command line args correctly. I looked at
ARGV[] and this was showing empty.

I therefore just tried running the following

use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";

No matter what I pass on the command line, single quoted , double
quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].

U:\PerlScripts>argv.pl "aaaaa" "ddddd"
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg0=
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg1=

The only command I can get to work is as follows

U:\PerlScripts>perl -le "print $ARGV[0]" "dddddddddd"
dddddddddd

U:\PerlScripts>

Having been away from perl for some time I guess I'm missing something
fundamental here. Perl is ActiveState 5.8.3
 
J

Jürgen Exner

Niall Macpherson said:
use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";

No matter what I pass on the command line, single quoted , double
quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].

Check if the command line arguments are being passed to the application
in the file extension bindings:

In Explorer go to 'Tools' -> 'Folder Options' -> 'File Types'.
Select 'PL file' -> click 'Advanced' -> select 'Open' -> click 'Edit' ->
check 'Application used to perform action'. The value should end with
the parameter list:

[pathToPerlInterpreter]\perl.exe" "%1" %*

jue
 
A

A. Sinan Unur

I've recently returned to using perl after a year or so away.
s/perl/Perl/

I therefore just tried running the following

use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";

No matter what I pass on the command line, single quoted , double
quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].

U:\PerlScripts>argv.pl "aaaaa" "ddddd"
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg0=
Use of uninitialized value in print at U:\PerlScripts\argv.pl line 3.
arg1=

The only command I can get to work is as follows

U:\PerlScripts>perl -le "print $ARGV[0]" "dddddddddd"
dddddddddd

U:\PerlScripts>

Having been away from perl for some time I guess I'm missing something
fundamental here. Perl is ActiveState 5.8.3

Most likely, this has nothing to do with Perl but with the fact that the
file association for .pl is not correctly set up (in the Windows
registry).

Make sure the following match the output of the same commands on your
system.

E:\> assoc .pl
..pl=Perl

E:\> ftype Perl
Perl="C:\opt\Perl\bin\perl.exe" "%1" %*

My guess is that on your system, the trailing %* will be missing. You
should be able to fix that. You can get help on the ftype command by
typing

E:\> ftype /?


Sinan


--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
A

Andrew Rich

Take another stab in the dark

#!/usr/bin/perl
use strict;
use warnings;
print "arg0=" , $ARGV[0], "\n", "arg1=", $ARGV[1], "\n";

../args.pl andy barry
arg0=andy
arg1=barry

Where you missing the command interpreter ? in line 1
 
J

Jürgen Exner

[Please no TOFU, trying to repair]
Andrew Rich said:
Niall Macpherson said:
No matter what I pass on the command line, single quoted , double
quoted or unquoted I never get anything in $ARGV[0] or $ARGV[1].

U:\PerlScripts>argv.pl "aaaaa" "ddddd"
[...]
Take another stab in the dark
#!/usr/bin/perl
use strict; [...]
Where you missing the command interpreter ? in line 1

As evidenced by the command prompt
U:\....
the OP is using Windows. Therefore the shebang line will happily be
ignored.

jue
 
N

Niall Macpherson

Many thanks jue and Sinan

The trailing %* was missing and adding it has fixed the problem
 
D

Dr.Ruud

Jürgen Exner schreef:
As evidenced by the command prompt
U:\....
the OP is using Windows. Therefore the shebang line will happily be
ignored.

"ignored" is too strong: any options, like -T, can still be obeyed.
 
J

Jürgen Exner

Dr.Ruud said:
Jürgen Exner schreef:


"ignored" is too strong: any options, like -T, can still be obeyed.

Ok,
s/the/this/
because the one offered didn't have any options.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top