Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   perl scripts fail to read commandline arguments (http://www.velocityreviews.com/forums/t891313-perl-scripts-fail-to-read-commandline-arguments.html)

reeddeer 03-11-2005 11:33 PM

perl scripts fail to read commandline arguments
 
Using XP, SP2, all my previously working perl scripts now fail to
notice any of the commandline arguments. I've never heard of this
happening. I've rebooted the box and removed, then reinstalled
ActivePerl-5.8.1.807-MSWin32-x86.msi, tested again and rebooted again.
I've wondered if SYSIN could be mis-directed? Batch files accept
arguments readily.

Here is a testarg.pl program which fails to detect any arguments:

use strict;
use warnings;

# -------------------------------------
# Main Program
# -------------------------------------

if(@ARGV > 0 )
{
print "1st arg: ~~$ARGV[0]~~ \n";

if ($#ARGV > 1 ) {
print "2nd arg: ~~$ARGV[1]~~ \n";
}
if ($#ARGV > 2 ) {
print "3rd arg: ~~$ARGV[2]~~ \n";
}
print "Done, read ~~$#ARGV~~ args.\n";

}

else
{
die "No arguments were seen! \n";
}
# -- end ------------------------------


I try it with:
testarg argue1 param2
and get: No arguments were seen!
testarg "argue1" "param2"
and get: No arguments were seen!

My co-workers have similar machines and they don't have the problem,
the same test script prints the arguments given.

Any suggestions? tips?
Thanks,
Reeddeer


reeddeer 03-12-2005 12:04 AM

Re: perl scripts fail to read commandline arguments
 
I found the problem: in "File Types" the .PL extension was opened by
"\path\perl.exe" instead of by: "\path\perl.exe" "%1" %* so it did
not open the perl script _with_ the arguments that were passed. Sorry
for using the bandwidth, but perhaps this will help someone else in the
future.

Thanks,
reeddeer


Martin Kissner 03-12-2005 11:01 AM

Re: perl scripts fail to read commandline arguments
 
reeddeer wrote :
> Using XP, SP2, all my previously working perl scripts now fail to
> notice any of the commandline arguments. I've never heard of this
> happening. I've rebooted the box and removed, then reinstalled
> ActivePerl-5.8.1.807-MSWin32-x86.msi, tested again and rebooted again.
> I've wondered if SYSIN could be mis-directed? Batch files accept
> arguments readily.
>
> Here is a testarg.pl program which fails to detect any arguments:
>
> [snipped]


look at this, I hope it helps:

shell > perl -e 'if($#ARGV > -1) { print $#ARGV +1," arguments were passed\n"}
else { print "no arguments were passed\n"}' hello world
2 arguments were passed

shell > perl -e 'if($#ARGV > -1) { print $#ARGV +1," arguments were passed\n"}
else { print "no arguments were passed\n"}'
no arguments were passed

The index of the last argument is in $#ARGV, so $#ARGV +1 returns the
number of arguments

Best regards
Martin

--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'

A. Sinan Unur 03-12-2005 06:10 PM

Re: perl scripts fail to read commandline arguments
 
Martin Kissner <news@chaos-net.de> wrote in
news:slrnd35j08.1nm.news@maki.homeunix.net:

>
> The index of the last argument is in $#ARGV, so $#ARGV +1 returns the
> number of arguments
>


And, of course, one could just use @ARGV in scalar context to get the
number of arguments passed.

Sinan

Martin Kissner 03-12-2005 08:44 PM

Re: perl scripts fail to read commandline arguments
 
A. Sinan Unur wrote :
> Martin Kissner <news@chaos-net.de> wrote in
> news:slrnd35j08.1nm.news@maki.homeunix.net:
>
>>
>> The index of the last argument is in $#ARGV, so $#ARGV +1 returns the
>> number of arguments
>>

>
> And, of course, one could just use @ARGV in scalar context to get the
> number of arguments passed.


Yes, of course. Thanks for pointing out.
This is actually what the OP does in the first if query 'if(@ARGV > 0 )'
(not exactly. but kind of).

But then he does

if ($#ARGV > 1 ) {
print "2nd arg: ~~$ARGV[1]~~ \n";
}

where the query should be

if ($#ARGV > 0 )
or
if ($#ARGV => 1 )
or even
if (@ARGV > 1 )

and so on.
Finally

print "Done, read ~~$#ARGV~~ args.\n";

should be

print "Done, read ~~",$#ARGV+1,"~~ args.\n";

to return the number of arguments correctly (of course scalar @ARGV
would return the same result as $#ARGV+1 does).
The rest of the script seems all right to me.

Best regards
Martin

--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'

Martin Kissner 03-13-2005 12:26 AM

Re: perl scripts fail to read commandline arguments
 
Abigail wrote :
> Martin Kissner (news@chaos-net.de) wrote on MMMMCCXI September MCMXCIII
> in <URL:news:slrnd36l58.2uc.news@maki.homeunix.net> :
> ??
> ?? where the query should be
> ??
> ?? if ($#ARGV > 0 )
> ?? or
> ?? if ($#ARGV => 1 )
>
> I guess you mean
>
> if ($#ARGV >= 1 )


Yes, I do; sorry for the typo.

Best regards
Martin

--
perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
[29,77,98,111,105,29],[100,93,95,103,97,110]];
for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'


All times are GMT. The time now is 09:24 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.