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

I call a script at the unix prompt by typing ->perl script.pl
But how do I pass parameters into the script which can then be intercepted by the param() function.
Also, I comment out -Tw from the first line of the script when calling from the command line - should I be doing something else?

Replies are listed 'Best First'.
Re: Calling cgi from the command line
by thpfft (Chaplain) on May 05, 2002 at 23:38 UTC

    If you use CGI, as you appear to, then you'll be prompted for parameters when the script runs from the command line. Enter them in parameter=value pairs with a return after each, and hit ctrl-D when you're done to continue running the script. If you don't use CGI.pm, this would probably be a good time to start.

    And you will need to remove the taint flag, else perl will rightly complain that it's too late for that. You can use it on the command line instead. I'd leave the warnings flag there though, if I were you. Slightly defeats the object to use it only when you can't see the output...

    update or, as wardk says, by appending name=value pairs, which is easier when you have to do it repeatedly, but i seem to have got out of the habit. still depends on using CGI.pm. all the details are in the docs.

      And you will need to remove the taint flag, else perl will rightly complain that it's too late for that. You can use it on the command line instead. I'd leave the warnings flag there though, if I were you. Slightly defeats the object to use it only when you can't see the output..

      I would advise against this, leave the -T in the program and add it as a command line switch to avoid the 'Too late for Taint' message. If you run around adding and removing the -T ,you open your script up for the mistake of forgetting to put it back in.

      perl -T script.cgi name=value



      grep
      Unix - where you can throw the manual on the keyboard and get a command
Re: Calling cgi from the command line
by wardk (Deacon) on May 05, 2002 at 23:41 UTC
    pass name=value pairs
    perl script.pl parm1=data parm2=data2
Re: Calling cgi from the command line
by mephit (Scribe) on May 06, 2002 at 05:16 UTC
    perl scriptname.pl param1="foo" param2="bar"
    Well, it works on Linux anyway. 'perldoc CGI' explains it.

    HTH