Thanks for the tip about escaping it all at once, instead of line by line.
I ended up doing this on my website, since it'll always be hosted on
Apache/Linux (I think):

local $/ = undef;
print escape_html(<FANFIC>); # from Apache::Util

That script is now up to 45 requests per second (it was originally 30 reqs
per second when it called $Server->HTMLEncode line by line), and I have
yet to implement caching.

BTW, I just took a look at the code for $Server->HTMLEncode():

    $toencode=~s/&/&amp;/sg;
    $toencode=~s/\"/&quot;/sg;
    $toencode=~s/>/&gt;/sg;
    $toencode=~s/</&lt;/sg;

Wouldn't it be more efficient to do something like this?

%map = (
  '&' => '&amp',
  '<' => '&lt',
  '>' => '&gt',
  '"' => '&quot'
);

$toencode =~ s/(&|<|>|\")/$map{$1}/g;

The mapped regexp wasn't my idea actually---see
http://www.mail-archive.com/modperl@apache.org/msg18587.html for the
original post where I learned about this. I was writing an HTML escape
function and Stas Bekman told me "your code is highly inefficient (you run
s/// 3 times!!!)".


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to