Click to See Complete Forum and Search --> : Include.. ?


Maico
08-26-2005, 05:51 AM
Hi,

Ive got a problem..

I'm making something in CGI-PERL but now i want to 'include' a footer and a header on the main site.

But this code dousn't work :

include("pages/header.cgi");

I also tried :

$header = "[your file here]";

print "Content-type: text/html\n\n";
open(FILE,"$header");
while() {
print $_;
}

But it just freezes then..

Can some one help me out ?


Thnx

drhowarddrfine
08-26-2005, 09:17 AM
You are trying to write C code for Perl. It's not exactly the same thing. There is no "include" statement like in C. You must use "use" or "require".

Maico
08-26-2005, 09:56 AM
You are trying to write C code for Perl. It's not exactly the same thing. There is no "include" statement like in C. You must use "use" or "require".

Oke.. but what command would that be then..
I'm a kind a n00b :rolleyes:

drhowarddrfine
08-26-2005, 02:53 PM
Well, "use" and "require" are what you need. They are similar to saying "include" in C. Go here (http://learn.perl.org/library/beginning_perl/) to read about subroutines and modules.

Charles
08-26-2005, 05:14 PM
#!c:\perl\bin\perl.exe

use strict;
use CGI qw (header);
use CGI::Carp qw(fatalsToBrowser);

my $include = 'test.html';

open (INCLUDE, $include) or die "Include file $include not found.\n";

print header;
print $_ while (<INCLUDE>);