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

Try without the x modifier on the regex

#!/usr/bin/perl use strict; use CGI; use File::Slurp qw/read_file/; my $includepath = "c:/temp/"; my $file_to_read = 'aa.html'; my $html = read_file($file_to_read); $html =~ s{<!--#include file="([^"]+)"-->} {&add_template($includepath.$1)}gei ; print CGI::header(); print $html; sub add_template{ my $file = shift; if (-e $file){ return read_file($file); } else { warn "$file not found"; return '<!-- $file not found to include -->'; } }
poj

Replies are listed 'Best First'.
Re^4: displaying html file in the browser using perl
by tsdesai (Acolyte) on Dec 19, 2016 at 19:06 UTC
    Hiya, I have tried your code. But i guess the problem is i have also comments in the page like <!-- start of the page -->. it tries to think start of the page is the file and fails . so something which specifically looks for include file rather than looking for comments in the page. I still think my reg expression is not right.At the moment its
    $html =~ s{<#include file="([^"]+)"}{&add_template($1)}gei;
    I would really appreciate any help on this . Many Thanks,
      #$html =~ s{<#include file="([^"]+)"}{&add_template($1)}gei; # remove < ^ here $html =~ s{#include file="([^"]+)"}{&add_template($1)}gei;
      poj
        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