Gossamer Forum
Home : General : Perl Programming :

Include files in site_html.pl? Is this the correct way?

Quote Reply
Include files in site_html.pl? Is this the correct way?
I would like to include some files in site_html.pl, but is this the wright way?

And is the !$header necessary?
(in the whole site_html.pl I put 6 $header)

And can I use FILE for earch include, or do I have to use FILE1, FILE2, FILE3?

Code:

if (!$header) {
open (FILE, "/opt/guide/header.txt") or die "Can't open header file: $!";
$header = join ("", <FILE> );
close FILE;
}

if (!$nav) {
open (FILE, "/opt/guide/nav.txt") or die "Can't open nav file: $!";
$nav = join ("", <FILE> );
close FILE;
}


if (!$footer) {
open (FILE, "/opt/guide/footer.txt") or die "Can't open footer file: $!";
$footer = join ("", <FILE> );
close FILE;
}

[This message has been edited by chrishintz (edited March 04, 1999).]
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
Have a look at gossamer-threads.com/scripts/forum/resources/Forum3/HTML/000403.html



------------------
Jason
Extreme mtb
http://extreme.nas.net
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
That does NOT answer my question!!!
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
Here's the solution:

1. in the very top of your 'site_html.pl' include this line:

require "/home/path/to/the/file.pl";

2. set some stuff in your 'file.pl':

$my_site_menu = qq~
<a href="/New/">News!</a>
<br><a href="/Cool/">Popular Links</a>
<br><a href="/cgi-bin/jump.cgi?ID=random">Random Link</a>
<hr ALIGN=LEFT SIZE=1 NOSHADE WIDTH="95%">
<a href="/cgi-bin/add.cgi">Add URL</a>
<br><a href="/cgi-bin/modify.cgi">Modify URL</a>
~;

$my_header = qq~
<h1>HEADER</h1>
~;

$my_footer = qq~
<h2>FOOTER</h2>
~;

3. And then just add '$my_site_menu', '$my_header' & '$my_footer' where you want to be shown in 'site_html.pl'
It's what I do, and it works fine.

Regards,

Pasha
http://find.virtualave.net

------------------
-[ It's just another night; good morning Webmasters! ]-
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
That looks like it would work. The !$header is neccessary only if the subroutine is going to be called multiple times and $header is global in scope (all it does is say if $header exists, don't load the file again).

You might want to choose different names then header, footer, nav if these are globals used in Links. Prefix them with something so you know they are globals.

You can use the FILE filehandle again as long as you close it the first time.

Cheers,

Alex
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
THANKS ALEX,

Thats just the answer is needed :-)
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
And there's another way, if you want SSI:

================
plugit.cgi Smile
================
#!/usr/bin/perl
#
##############################################################################
# Plug It! v1.0 #
# Copyright (c) 1998 by Mike's World. All Rights Reserved. #
# http://www.mikesworld.net #
# mike@mikesworld.net #
# #
# You should carefully read all of the following terms and conditions #
# before using this program. Your use of this software indicates #
# your acceptance of this license agreement and warranty. #
# #
# This program is being distributed as freeware. It may be used and #
# modified free of charge, so long as this copyright notice, and the header #
# above remain intact. Please also send me an email, and let me know #
# where you are using this script. #
# #
# By using this program you agree to indemnify Mike's World from any #
# liability. #
# #
# Selling the code for this program without prior written consent is #
# expressly forbidden. Obtain permission before redistributing this #
# program over the Internet or in any other medium. In all cases #
# copyright and header must remain intact. #
##############################################################################

# Installation -
#
# 1 - Upload in ascii mode to your cgi-bin
# 2 - Chmod 755 plugit.cgi
# 3 - Create a file that holds everything you would like to be
# displayed called plugit.txt and upload that to the same directory.
# 4 - Whatever page(s) you want Plug It! to show up in, include this
# SSI line <!--#exec cgi="/cgi-bin/plugit.cgi" -->

{
&PlugIt;
}

sub PlugIt
{
$plugit="plugit.txt";

open (PLUG,$plugit) &#0124; &#0124; die "can't open $plugout";
$plugit="";
while (<PLUG> ){$plugit .=$_;}
close(PLUG);

print "Content-type: text/html\n\n";
print "$plugit";

}
1;


=================
plugit.txt Smile
=================
<h1>Header</h1> <p> <a href="Menu">Menu</a> </p> <h2>Footer</h2>

=================
Now just insert the following anywhere you need:
<!--#exec cgi="/cgi-bin/plugit.cgi" -->

But before using this script, you should first check out http://www.mikesworld.net for more information.


Regards,

Pasha
http://find.virtualave.net
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
If you have SSI access, why on earth wouldn't you just use:

<!--#include virtual="/file.txt" -->

Seems to me that would be much eaiser and a lot faster.

Cheers,

Alex
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
Alex, I am just trying to make life more difficult Smile
You're right, <!--#include virtual="/file.txt" --> is much easier.

Wink
Quote Reply
Re: Include files in site_html.pl? Is this the correct way? In reply to
YOU GUys confused me when I m reading this hahahahah

hahahahah

but ALAX s short answere Always Make Sense TO ALL hehehehehe


heehee

Thanks Alax!