Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script and SSI...

Status
Not open for further replies.

devilpanther

Programmer
Oct 8, 2004
57
IL
I know in order to execute a script with SSI I need the calling page to end with .shtml
But what if I have a perl script displaying html, can I in some way call from that html (inside the perl script) to SSI?

Or is there some other way I can embed printed value of other script into my perl html output.


Thank you.
 
You can "require" the script, as long as it ends in 1;

You can only fire SSI's from the webserver, when perl is processing a cgi script it's too late to call the SSI.

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
If your SSI script called a subroutine which produced the output then yes, because you could have the normal scripts include the module and then call the sub catching the returned HTML to be included.... I use this method myself.

I'll explain...

I have some .shtm files which have an SSI include to execute the menu.cgi.

in menu.cgi it calls a routine in my "Menu Module", which genrates the menu HTML and then returns it to the .shtm to display.

But I also have scripts which produce HTML but I want to include the menu so I use the same "Menu Module", call the required sub, capture the returned data into a sting and include that in the HTML output.

So I have one sub which creates my main menu and can be included in either my .shtm files or called by other scripts for output.

Well that's how I do it :)



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
PaulTEG can you please explain, what do you mean by 1?

1DMF, my web site is database based: I have to display everything from the script first...
Is there somesort of perl module that can help me with that instead?


Thanks again
 
I have to display everything from the script first

Can you explain why?

If you call a script, within that script you can do what ever you like before you print anything to the screen.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Here is what I'm trying to do:

I have the main script to display pages from the database: index.cgi

And I would like from now and then to be able to add another script output to that index.cgi... like a counter for example, but without changing the index.cgi

So like index.cgi displays a page from the DB and that DB page will tell where the counter should come.
 
script2.cgi
Code:
#!/usr/bin/perl

print "<table><tr><td>x</td><td>y</td><td>z</td></tr></table>";
1;

index.cgi
Code:
#!/usr/bin/perl
....
#find where you want to put the table
require script2.cgi;
#carry on

Hope that makes sense
Regards

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
you don't want to edit index.cgi, but you want the content of that script to change?

either you edit the index script or you change the way index.cgi outputs the data.

if it outputs a string of the HTML to display ANY scripts can capture it use it.

you cannot have a script print to the screen and then insert data, prior to that printed data.


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF, isn't there any way I can make the web server to treat my perl script as an SSI?
 
not if it's a running perl scripts, AFAIK , PERL cannot call SSI, but why, surely the SSI calls a PERL scripts, so forget SSI, and merge the scripts via a module, an include , what ever. As Paul has shown or I do it this way..

This is the script including the menu.

Code:
#######################
# Use ssplmenu module #
#######################
use ssplmenu;

# Build HTML
my $catlist = "
<HTML>
<HEAD>
<TITLE>SSPL Albums Catalogue</TITLE>

<script>
function shopcart() {

shop JS
}

</script>
</HEAD>

<BODY  BGCOLOR=\"#000000\">
";

# Add Menu
$catlist .= &getMenu;

this is an SSI including the menu...

Code:
<HTML>
<HEAD>
<BODY>
<!--#EXEC CGI="/cgi-bin/SSPL/menu.cgi -->

this is the menu.cgi
Code:
#######################
# Use ssplmenu module #
#######################
use ssplmenu;

# Output Menu
my $menu = &getmenu;

# return menu code
$menu;

this is the module...

Code:
##########################
# Main SSPL Menu Routine #
##########################
sub getMenu {

# Build HTML 
my $html = "
<!--- Start of menu --->
<table>
    <tr><td>
HTML FOR THE MENU
</td>
</tr>
</table>
<!--- end of menu --->
";

# Return Menu
$html;

so the module has the menu code.

any script can call &getmenu and get the menu HTML or any SSI can call menu.cgi and get the menu HTML.

hope this makes sense

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top