Can you trust the source of the XML to never change (whitspace, attributes, CDATA, namespaces, comments, etc.), and can you trust the program that's doing the sanitization to never change its output either? What's wrong with installing modules, especially such helpful ones?

Yes, I can. The program whose output I am using is only capable of writing about a dozen specific tags, and there will never be any attributes CDATA, namespaces, or such.

For what I want to do in this specific case, it is just far easier (and more understandable for me) to simply use:

$fragment =~ s/<foo>\d+<\/foo>/'<foo>' . $i++ . '<\/foo>'/eg;

I don't need anything more complicated to accomplish this. While I already learned something regarding this, there is no shortage of things I don't know about perl (even having used it for years for quick tasks, I would still classify myself as a novice). Given the increasing popularity of XML, I am certain there will plenty of opportunities for me to learn more advanced techniques in the future, including specialized modules. :)

Searching for "html tidy" on Google and CPAN shows lots of different options (I haven't used any of them, so I can't give you recommendations). Plus, I wonder why you're asking about such a program, if you said above your XML is already sanitized?

As I noted, that was a "side question" (meaning it has absolutely nothing to do with what I was asking about sequential substitutions). It is for something completely different, and you seem to know quite a bit about the subject, so I just thought it would be a good time to ask that question. :)


In reply to Re^4: sequential substitutions by Anonymous Monk
in thread sequential substitutions by Anonymous Monk

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.