in reply to Why doesn't @ARGV work?

This is how I would do it:
use strict;
# @ARGV is an array, so number of args in an array is $#ARGV+1
# The last element position is $#ARGV.
# Also I like to line up brackets and braces. 
my $numargs = $#ARGV+1;
print "numargs = $numargs\n";
if ( $numargs > 0 )
{ for my $a ( @ARGV ) # $a gets assigned to each item in @ARGV.
   { print "  $a\n"; } 
}
Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

Replies are listed 'Best First'.
Re^2: Why doesn't @ARGV work?
by LloydRice (Beadle) on Jul 17, 2014 at 12:34 UTC

    Thanks for all the inputs. The first thing I did was to download a fresh copy of the ActiveState .msi. I tried "repair" and when that didn't help, I tried removing the old install and reinstall (all using the ActiveState installer).

    The association seems to be OK (because it does run the correct script). I tried adding some other things to the script, defining my own @mylist = (1,2,3);, printing @INC and %ENV. All of that worked fine. There were a couple of other suggestions relating to assoc. I will try those, but that does not seem to be the issue.

      Now, I'm really confused !!!

      I just set up another new Gateway, identical to the Win8 system I was using yesterday and installed Perl as before. I get the same result as yesterday:

      numargs = 0

      Obviously, the correct little Perl script is running. At the moment, I just shut that machine off, and I will try the suggestion of using $#ARGV-1 instead of @ARGV. But I would not expect that to make any difference.

      This result seems to rule out any issues with the op sys on the other machine. I opened a standard CMD window, typed the program using Notepad, and ran it. So there was nothing else installed, otherwise a virgin machine.

      Has anybody else has any issues with Win8?

        There was one reply yesterday about possible issues with batch or pl2bat. This is using neither of those. I am familiar with the %* argument in batch files and I did once look at pl2bat. But now, I am running the Perl script via the Perl system directly from the CMD command line.