Click to See Complete Forum and Search --> : executing code from another cgi file?


DJRobThaMan
11-16-2005, 08:56 PM
So, here's yet another question for you perl experts.

I remember reading on a site somewhere while I was trying to figure out something completely different that it is possible to use the use function to include a .cgi file that is in your cgi-bin so that you can use sub-routines from those files within another cgi file. I'm still trying to find it but to no avail yet.

eg

#! perl/perl.exe;
use CGI;
use "file.cgi"; <-----------

Is this possible (I know the current syntax is incorrect if so)?

If this is 100% not possible is there another way to access and execute code from another cgi file? That's basically what I want to do.

Thanks a lot,
Douglas

DJRobThaMan
11-16-2005, 11:15 PM
Holy crap!!!!!!!!

I actually figured something out all by my lonesome!

I just needed to use require instead of use.

Douglas

gube
11-16-2005, 11:52 PM
Hi,
You can write all the subroutines in .pm file and call it in the .cgi file..using use / require modulename.pm this is the better way of calling methods into cgi file..

Regards,
Gube...
language(perl | die)..

DJRobThaMan
11-16-2005, 11:57 PM
Could I save the .pm file in the cgi-bin folder and still call it that way (ie. filename = file.pm in the same folder with all my scripts and statement = use file;) ?

Douglas

DJRobThaMan
11-16-2005, 11:58 PM
hmmm..... random smiley showing up in my msg, strange

gube
11-17-2005, 01:21 AM
Yeah sure.. you can save .pm file and it can be in cgi-bin folder no problem..Else if you have to place any folder apart from .cgi folder place you can create as package..

You go to the link : http://perlmonks.com/?node=Tutorials and read more how to create module and packages. It's better you to create cgi files..

Regards,
Gube...
language(perl | die);