Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

passing parameters from the command line

by TomGeukens (Initiate)
on Dec 08, 2005 at 00:21 UTC ( [id://515085]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I'm having a really dumb problem with running scripts from the command line when I have to pass in parameters/options into a script from the command line. My script works perfectly when I type:
c:>perl script.pl <option>
but when I just run it without the 'perl' command, it always gets a zero-value passed in. As long as there is no need to pass in parameters, no problem, but the
$option = hex(shift);
does not work on my system. I'm using WinXP, and believe to have set the correct environment variables . . . anything else to tweak? thanks, TGe

Replies are listed 'Best First'.
Re: passing parameters from the command line
by GrandFather (Saint) on Dec 08, 2005 at 00:44 UTC

    Check that the correct association has been made with '.pl'. Assuming that you are using an ActiveState install of Perl, right click on a .pl file and select "Open With|Choose Program..." and check that Perl Command Line Interpreter is selected. If not, select it (or browse to perl.exe, probably in c:/Perl/bin) and check the 'Always use the selected program to open this kind of file' check box.

    FYI, it works fine both ways for me.


    DWIM is Perl's answer to Gödel
Re: passing parameters from the command line
by NetWallah (Canon) on Dec 08, 2005 at 05:36 UTC
    Expanding on Grandfather's explanation, check the association for ".pl". (In Explorer, do Tools->Folder Options -> File Types, select .pl) The default action should be "Run".

    Now look at how the executable for "Run" is configured.
    In my case, it says:

    "D:\Perl\PXPerl\bin\perl_pause.bat" "%1"
    Notice that only ONE parameter "%1" is being passed, and that is the name of the program. The args you want passed would not work on my system, and I get the results you are getting, and the message "Use of uninitialized value in concatenation (.) or string at ..." when attempting to print $ARGV[0]".

    The fix is to change the executable line to

    "D:\Perl\PXPerl\bin\perl_pause.bat" "%1" %2 %3 %4 %5 %6 %7 %8 %9

         You're just jealous cause the voices are only talking to me.

         No trees were killed in the sending of this message.    However, a large number of electrons were terribly inconvenienced.

      Hey Guys, thanks a lot for the information. Messing around with the executable line did the trick!!!
Re: passing parameters from the command line
by l3v3l (Monk) on Dec 08, 2005 at 00:33 UTC
    can you just use: $opt = $ARGV[0] || "default value for option"; instead of shift or is there something else going on in your script that requires you to use shift?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-20 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found