Without knowing what your HTML file contains, I cannot reproduce your problem. Please replace the reading of the HTML file into $html by hardcoding the value of $html. For example:
my $html = <<'HTML'; <html> <body> <!--#include file="somefolder/cc.html" --> </body> </html> HTML
See also SSCCE for an incredibly effective technique on how to debug things and provide information for others so that they can diagnose your situation and suggest approaches.
When I modify your script to be self-contained, it does just what I expect:
use strict; use warnings; my $htmlfile ='/var/www/html/xx/xxx/1204.html'; my $html = <<'HTML'; <html> <body> <!--#include file="somefolder/cc.html" --> </body> </html> HTML #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\n"; my $display_file="$includepath$file"; print $display_file, "\n"; 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 -->"; } }
You will note that I changed the error message so that it outputs the value of $display_file. This is highly important as in your case, there may be a typo or a permissions error or something.
In reply to Re^9: displaying html file in the browser using perl
by Corion
in thread displaying html file in the browser using perl
by tsdesai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |