Now that I'm more comfortable with Perl, I'm going through some of my old Pascal programs and trying to rewrite them in Perl. Partly to web-enable them, and partly for practice.

I'm working on one now that reads a text file and creates an HTML file. The text file contains some accented letters (i.e. é). My first instinct is to use a substitution to replace the accented characters with the proper HTML equivalents (i.e. é), but the text file is about 200 kb and there are eight accents that I know of. Running every character (by line) through that many substitutions seems to be a lot more overhead than I want for a dynamic page.

I'm trying to find a method that can do this for me under the assumption that built-in methods are faster. It would also be nice to have a solution that doesn't require me adding another substitution everytime a new accent shows up in the text file. I tried Perl Monks, the Black Book, the Cookbook, and a few web sites. No luck yet.

Am I missing something, or do I have to build this from scratch? If so, then is there a smarter way than individual substitutions?

Thank you.


In reply to Looking for a Better Way to Substitute Characters (accents to HTML) by svsingh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.