in reply to Re^4: displaying html file in the browser using perl
in thread displaying html file in the browser using perl

#$html =~ s{<#include file="([^"]+)"}{&add_template($1)}gei; # remove < ^ here $html =~ s{#include file="([^"]+)"}{&add_template($1)}gei;
poj

Replies are listed 'Best First'.
Re^6: displaying html file in the browser using perl
by tsdesai (Acolyte) on Dec 20, 2016 at 08:41 UTC
    Thank you so much for your help. It seems to work they way it should and only looks for include file. But, still doesn't display the included file when i read aa.html on the browser. I have double checked the path and have tried to print only the included file and it does print the file individually. When i try to read with aa.html it just kind of ignores and doesn't print the included file. I have no idea what i am missing now. Many Thanks, T

      When "running from the browser", you need to use absolute path names. Instead of trying to open somefolder/cc.html, you will have to use /home/tsdesai/somefolder/cc.html for example.

        Thanks, I have absolute paths. Below is my entire code if it helps.
        use strict; use warnings; use File::Slurp qw/read_file/; use CGI; print CGI::header(); my $htmlfile ='/var/www/html/xx/xxx/1204.html'; #mainfile to read my $html =read_file($htmlfile); #path of the included file my $includepath="/var/www/html/xx/xxx/"; if ($html =~ s{#include file="([^"]+)"}{&add_template($1)}gei) { print "the file has include file"; print $html; } else { print "doesn't have"; print $html; } sub add_template{ my $file = shift; #print "$file"; my $display_file="$includepath$file"; # print $display_file; if (-e $display_file){ #print "$display_file"; return read_file($display_file); } else { # warn "$display_file not found"; return '<!-- $display_file not found to include -->'; } }
        The above code prints the main file which is 1204.html and then also detects that there is an included file given in the if condition but just doesn't print it. Not sure why. Many Thanks, T