Connecting Tech Pros Worldwide Forums | Help | Site Map

Including results from one CGI in another.

Kelicula's Avatar
Expert
 
Join Date: Jul 2007
Posts: 169
#1: Oct 22 '07
Is it possible to include the results from a cgi script in another cgi script?

Here is what I am trying to do.

cgi script 1, creates a web page dynamically depending on certain attributes of an external file.

I want my second cgi script to be able to "call" the first one, execute it and funnel the STDOUT into a namspace within the second file, to be included in that files STDOUT.

IE:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -T
  2.  
  3. use strict;
  4. use warnings;
  5. use CGI;
  6.  
  7. $| =1;
  8.  
  9. print header;
  10.  
  11. my $thing = `results from output of other cgi script`;
  12.  
  13. my $q = new CGI;
  14. print $q->p('some stuff',
  15.                 "$thing");
  16.  
Anyone know if this can be done?

eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 901
#2: Oct 22 '07

re: Including results from one CGI in another.


With perl there is always more than one way to do most things. Here is one way you can achieve what you want.

script 1
Expand|Select|Wrap|Line Numbers
  1. #/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6.  
  7. sub some_routine{
  8.  
  9.    my $return_var = "Hello";
  10.    return($return_var);
  11.  
  12. }
  13.  
  14. 1;
script 2
Expand|Select|Wrap|Line Numbers
  1. #/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. require 'path/to/script2.pl';
  7.  
  8. my $thing = &some_routine();
  9.  
  10. print $thing;
  11.  
  12. 1;
Kelicula's Avatar
Expert
 
Join Date: Jul 2007
Posts: 169
#3: Oct 23 '07

re: Including results from one CGI in another.


Excellent!! Thank you. It worked fine..
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 901
#4: Oct 24 '07

re: Including results from one CGI in another.


Quote:

Originally Posted by Kelicula

Excellent!! Thank you. It worked fine..

You are welcome! Glad to help.
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#5: Oct 24 '07

re: Including results from one CGI in another.


"require" and "use" are very important functions to learn how to use with your perl programs. Especially if you want to write modular scripts or write modules that can be used in any script.
Kelicula's Avatar
Expert
 
Join Date: Jul 2007
Posts: 169
#6: Oct 25 '07

re: Including results from one CGI in another.


Quote:

Originally Posted by KevinADC

"require" and "use" are very important functions to learn how to use with your perl programs. Especially if you want to write modular scripts or write modules that can be used in any script.

Yes, I am not able to write my own "module" yet. But I've been checking out some source code on other modules. It seems like a new language. Their are some terms that I'm not familiar with. "bless", "croak" etc...
So I can't really take advantage of "use" yet.

I am currently building a CMS so to speak with Template Toolkit.

I would very much appreciate any info (hint hint...a new "article") on creating modules...

once again,
Thanks to all!!
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 901
#7: Oct 25 '07

re: Including results from one CGI in another.


perldocs have a some nice tutorials on this. Also, Object-Oriented Perl from O'Reilly's

perlboot
perltoot
perltooc

There a several books you can buy to help. This is what I have done. Going broke too. :)
Kelicula's Avatar
Expert
 
Join Date: Jul 2007
Posts: 169
#8: Nov 15 '07

re: Including results from one CGI in another.


Quote:

Originally Posted by eWish

perldocs have a some nice tutorials on this. Also, Object-Oriented Perl from O'Reilly's

perlboot
perltoot
perltooc

There a several books you can buy to help. This is what I have done. Going broke too. :)

I know what you mean! I got CGI programming, Template Toolkit, Programming the perl DBI, and Practical mod_perl from Oreilly the other day...

Haven't eaten dinner since!
Kust kidding, there is alot of good information in there.
I am looking forward to digesting it all.

Thanks.
Reply