It is longtime for me to review my question,I find above answer.
I think I should write something about it:
My sample template file(xml) is about 10kB,and my out put file is about 12kB.Each xml file contain 30 variable to replace,and my database's table contain 44 column(about 2000char and 4 text type column).My program cycle a table to create html files,each record create a file from 12 template files.
I think your suggestion is correct,because my file has some characters coding by UTF-8 or GB2312.Maybe Text::Template can not treate it correctly.I didn't try to confirm it.
To avoid hacking code of Text::Template,I wrote this code to instead Text::Template:
# Original I use Text::Template to get $Text,
# I replace it by my owner subroutine.
my $Text=GetTextFromVar($mark,$linehash);
sub GetTextFromVar
{
my $mark=shift; # template file's name
my $linehash=shift;
if($CurrentTemplateFile ne $mark)
# <- if the template file has been loaded into momory,don't load it next
{
# old use : $Template=Text::Template->new(TYPE=>'FILE',SOURCE=>$mark);
open(FH,'<',$mark);
$CurrentTemplateFile=$mark;
local $/=undef;
$CurrentTemplateContent=<FH>;
}
# old use : return $Template->fill_in(HASH=>$linehash);
# old usage create memory leap
my $content=$CurrentTemplateContent;
while(my ($key,$value)=each(%$linehash))
{
if($key=~m/^\w+\d*$/)
{
$content=~s/\{\$$key\}/$value/g;
}
}
return $content;
}
It takes 30 minutes to cycle 10000 record.Because I don't need to create html file online,that's enough.
Thanks for your help.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.