CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Passing parameters to a perl-cgi script using a url


New User

Jan 5, 2016, 2:10 PM

Post #1 of 3 (1377 views)
Passing parameters to a perl-cgi script using a url Can't Post

Hello, I'm not a perl programmer in anyway but i've got to do some conversion to an existing very large perl script that is currently running on a linux server. I'm pretty much stuck and would greatly greatly appreciate some help as I try to do this. Was very glad to find this forum.

I'll try to explain this the best I can. I hope it makes sense.
As I mentioned this perl script I need to change is very long but has many comments and many different options to set for testing etc. It does a lot of things that I really don't need to change. I just need to get it to run on a different server by calling in a different way and with it using a different database.

The main changes I need are 1) The way the script is being called and 2) connecting to a different oracle database than it is currently using.

Currently the way the perl script gets called is that there is a screen when the user clicks a button It makes a call to a small shell script. The shell script contains a few lines that set up environmentals - path, perl5lib, oracle_sid, oracle_home, ld_library_path etc. After defining this environmentals the last line of the shell script does the actual call to the perl script which is running on the server. This line is:

/opt/software/pcs/fame_3.0/perl/sched tran_id $1 is the name of the perl script and tran_id $1 is just passing
a parameter to the script , the parameter name is tran_id and the value is in $1, so it would actually look like this:

/opt/software/pcs/fame_3.0/perl/sched tran_id 3997

(the value of tran_id is 3997)

In the perl script ARGV handles the paramater/argument being passed.

Now the new way I need to call it is to call it using a url which opens a web browser and passes the parameter to the perl script. The perl script will be called as a .cgi Since i'm not calling a shell script first that sets up the environmentals i've defined them at the top of the perl script.
My question for now is how do I accept the parameter I am passing in the url, into the cgi/perl script. I was thinking it would still go into the ARGV array but I read somewhere that ARGV was for command line arguments only and would not work with parameters passed in a url. So, i'm not sure how to accept the parameter being passed in the url into the cgi script. The url will look like this. 3997

Can someone please tell me how I can access this parameter in the cgi script? Would really appreciate any help I can get.


Veteran / Moderator

Jan 5, 2016, 2:25 PM

Post #2 of 3 (1376 views)
Re: [jckrell] Passing parameters to a perl-cgi script using a url [In reply to] Can't Post

You can use the CGI module to parse the parameters.

Functional interface:


use strict;
use warnings;
use CGI qw(:standard);

my $tran_id = param('tran_id');

OO interface:


use strict;
use warnings;
use CGI;

my $cgi = CGI->new;
my $tran_id = $cgi->param('tran_id');

Your url is missing one character.

(This post was edited by FishMonger on Jan 5, 2016, 2:28 PM)

New User

Jan 5, 2016, 3:20 PM

Post #3 of 3 (1367 views)
Re: [FishMonger] Passing parameters to a perl-cgi script using a url [In reply to] Can't Post

Thanks for the information. I'll see what I can do.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives