Results 1 to 5 of 5
have another query
I want to call a function/subroutibe test_fucn from test.cgi for that I am doing following
#!/usr/bin/perl -w
use strict;
require "./test.cgi";
for my $reslt (@values) {
if ...
- 03-05-2008 #1Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
How to use a subroutine in mutiple perl scripts
have another query
I want to call a function/subroutibe test_fucn from test.cgi for that I am doing following
#!/usr/bin/perl -w
use strict;
require "./test.cgi";
for my $reslt (@values) {
if ( $rslt eq "red" ) { next; }
print "Value find";
&test_fucn;
}
But problem - It is giving me whole printable output from test.cgi which is not a part of test_fucn.
any suggestions, so that I can use only subroutine ?Switched to Scripting
- 03-05-2008 #2
You have two choices, and I don't think you will like either of them. :)
You can modify test.cgi, so that it contains nothing but functions, nothing that actually calls those functions.
You can copy the function you want to elsewhere, either in your main Perl script, or to some other file which you require instead of test.cgi.--
Bill
Old age and treachery will overcome youth and skill.
- 03-05-2008 #3Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
Ya, i already know this but the major.
This is not possible in actual that function is very big and calling many other(in same script) and I am creating a script which is I am going to put in cron job to run on regular basis.Switched to Scripting
- 03-05-2008 #4
Ok, let's call your new script, the one that contains the require statement, "fred".
Create a script which is just like test.cgi, except it contains basically only function definitions. Make sure you put all the function definitions there, and nothing else but the
at the beginning. We'll call this new script "barney".Code:#!/whatever/perl
Then, inside fred, require barney instead of test.cgi.
Then remove those function definitions from test.cgi. (Make sure you lay a copy of it aside, just in case!) Then, in test.cgi, require barney.
That way you have only one copy of the functions to maintain in case you wish to change (or fix) any of them.
This work for you?--
Bill
Old age and treachery will overcome youth and skill.
- 03-06-2008 #5Linux Newbie
- Join Date
- Jan 2008
- Posts
- 114
I used some other way
Instead of calling that function I called the whole script and passed parameter and it works for me..
ThanksSwitched to Scripting


Reply With Quote