ronrouth has asked for the wisdom of the Perl Monks concerning the following question:

I am seeing a problem with passing command line arguments to my script. I'm used to working on Unix, and this is the first time I've worked with Perl on XP.

The script is very simple

#!perl
foreach $line (@ARGV) ( print $line; }

When I run the script
> test.pl one two three

The ARGV array is always empty.
Is this an OS issue?
Where should I look next?

-confused

Replies are listed 'Best First'.
Re: MS XP and ARGV
by particle (Vicar) on Mar 05, 2002 at 01:39 UTC
    well, use strict; would have caught the typo ( print should be { print

    i'm using winxppro, perl 5.6.1. here's my test_cmdline.pl:

    #!/usr/local/bin/perl -w use strict; use diagnostics; $|++; for my $line (@ARGV) { print $line; }
    which results in:

    c:\>perl test_cmdline.pl one two three onetwothree c:\>

    ~Particle ;Þ

      well, use strict; would have caught the typo ( print should be { print

      This is a syntax error - the program would have failed to compile with or without use strict;. It is much safer to cut and paste example code than to retype it :)

      /J\

      Actually I do have the ";" after the " print $line" command.
      The type-o was in my message post.
Re: MS XP and ARGV
by gellyfish (Monsignor) on Mar 05, 2002 at 10:38 UTC

    It's a known problem with the windows shell and file associations (its not just XP but NT and 2000 as well) - you will find that it will work fine if you run the program as 'perl test.pl one two three'. One solution is to use the progran 'pl2bat' that is included with ActivePerl, this will wrap your Perl program as a batch file which can be executed directly and which doesn't suffer from the ARGV problem.

    /J\

      It may be a know problem, but not on my w2k box. I just ran this:
      #!/usr/bin/perl use strict; use warnings; for (@ARGV) { for (glob) { print $_,"\n"; } }
      and it worked as expected. The command line was 'pal.pl * web\*.pgn'.

      –hsm

      "Never try to teach a pig to sing…it wastes your time and it annoys the pig."
      Thank you!

      That was the correct resolution.
      Running the script as "perl test.pl one two three"
      returned the correct values.