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!

Parsing SSI 2

Status
Not open for further replies.

Extension

Programmer
Nov 3, 2004
311
CA
Hi,

I know Perl does not support SSI includes seamlessly, but some modules are available to integrate the feature.
I'm currently including some HTML files simply by converting them imto an array. This is fearly easy and clean without the aid of a module.

But if the included HTML file has some include statements in it, it will obviously won't work as Perl won't parsed it.
This is the problem I'm dealing with right now. So I was wondering if there is a module available that would parse the include statements in the included file ?

I hope it doesn't sound too complicated. But for experienced HTML guys, I guess it's should be easy too understand.
Any guidance would be appreciated.


Code:
	open(IncludeFile, "Include.html");
	my @Inc = <IncludeFile>;
	close IncludeFile;
	
	print @Inc;


Include.html
Code:
Some html code here
<!--#include virtual="anothreinclude1.html"-->
<!--#include virtual="anothreinclude2.html"-->
<!--#include virtual="anothreinclude3.html"-->

 
change the
Code:
<!--#include virtual="anotherinclude.pl"-->
to
Code:
require "anotherinclude.pl";

For cgi files, for HTML
change the
Code:
<!--#include virtual="anotherinclude.pl"-->
to
Code:
open INC, "anotherinclude.html";
while(<INC>) {
  print $_;
}

Is this what you mean?



Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
PaulTEG.

I need a way to parse the SSI includes that are in the Include.html file.

The Include.html file is as follow:
Code:
<!--#include virtual="anothreinclude1.html"-->
<!--#include virtual="anothreinclude2.html"-->
<!--#include virtual="anothreinclude3.html"-->

Since it's within an html file I cannot use the Perl require function and I also can't modify the html file.

Now, if I currently print the content of Include.html (either by printing file or converting it to an array), it will simply show the <!--#include virtual="anothreinclude1.html"--> as text and not parse the SSI statement.

Thank you for your help
 
okay, you just need to parse the content of the html file
Code:
open HTM, "<Include.html";
while (<HTM>) {
  if (index $_,"<!--#include virtual=" != -1) {
     @data=split /"/, $_;
     open INC, "<$data[1]" or die $!;
     while (<INC>) {
       print $_;
     }
     close INC;
  }
}
close HTM;
NOT TESTED, but should provide a basis to work on

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
that can provide a foundation, but unless the files to be included are in the same directory as the script that will not work as-is.
 
Thanks PaulTEG for your help. You concept is pretty good.

As KevinADC said, that will work if the files are located in the same directory. I will try to adapt it and well get back to you. (In my case, they are not always under the same dir)

Thanks again. Really appreciated.
 
however, if the include is to a PERL file, and the PERL produces HTML to be embebded then that won't work either ( i use this method for SSI alot!).



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
1DMF,
that was the first bit, parse out the filename for the include directive, and then use eval to require them

It's so crazy, it just might work ;)

--Paul

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Paul which bit of your code is executing the PERL include, to then parse the returned HTML?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
parse the filename out of the SSI directive
Code:
<!--#include virtual="anotherinclude.pl"-->
and then
Code:
eval ("require $filename");
granted, pathing issues may arise, but that's trivial

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
so eval ("require xyz"); actually executes the PERL code and returns you the result, cool as , have another star!

"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