Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Picking up command line arguments with Strawberry Perl: ARGV

by Aaron_A (Initiate)
on Jan 27, 2010 at 18:45 UTC ( [id://819994]=perlquestion: print w/replies, xml ) Need Help??

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

When I run the following programs (named args.pl) with ActiveState PERL (or under Unix):
#!/usr/bin/perl use warnings ; if ($#ARGV >= 0) {for ($n=0 ; $n<=$#ARGV ; $n++) {print("ARGV[$n]=$ARGV[$n]\n") ; } } else {print("No command line parameters found.\n") ; }
as follows:
> args.pl abc
the output is:
ARGV[0]=abc
But when I run it using StrawberryPerl 5.10.1 I get:
No command line parameters found.
Why? And what do I have to do to pick up the command line parameters?

Replies are listed 'Best First'.
Re: Picking up command line arguments with Strawberry Perl: ARGV
by ikegami (Patriarch) on Jan 27, 2010 at 19:16 UTC
    Your file association is broken.
    "C:\...\bin\perl.exe" "%1"
    but it should be
    "C:\...\bin\perl.exe" "%1" %*
    To fix:
    >assoc .pl .pl=Perl ---- \\\\ \\\\ vvvv >ftype Perl Perl="C:\...\bin\perl.exe" "%1" -------------------------- \\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\ vvvvvvvvvvvvvvvvvvvvvvvvvv >ftype Perl="C:\...\bin\perl.exe" "%1" %* Perl="C:\...\bin\perl.exe" "%1" %*
      This does not fix the issue.
Re: Picking up command line arguments with Strawberry Perl: ARGV
by Anonymous Monk on Jan 27, 2010 at 18:52 UTC
    But when I run it using StrawberryPerl 5.10.1 I get:

    Try

    perl file.pl args
    then go ahead and fix your ftype/assoc (type `help assoc' in cmd.exe )
Re: Picking up command line arguments with Strawberry Perl: ARGV
by Anonymous Monk on Jan 27, 2010 at 18:56 UTC
    perltidy -csc -otr -opr -ce -nibc -i=2 < prog.pl
    #!/usr/bin/perl -- use warnings; use strict; if (@ARGV) { for my $n ( 0 .. $#ARGV ) { print "ARGV[$n]=$ARGV[$n]\n"; } } else { print "No command line parameters found.\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://819994]
Approved by starX
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-25 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found