Your use of grep in a void context looks like a mistake. You realize that this does not change the content of @foots, don't you? I expect you want the list returned by grep to be the iterator in the following for loop:
+ for ( grep { $_->prev_sibling_text =~ m<([,.])\s*$> } @foots ) {

A mistake, or another rung on the learning curve. Or both. Thanks.

As for cases where the following sibling has no text (note: there are "prev_sibling()" and "next_sibling()" methods for elt objects), it may be a matter of understanding your document structure to determine whether you need to insert a new elt as a next sibling in order to move the punctuation text into that, or whether you can just assign text content (the punctuation) to the next sibling, whatever it may be.

This is my problem, and this is what I don't quite understand. Suppose I had data like this:

<a>Text text <b>Footnote code</b></a>

How, with XML::Twig do I add text between the </b> and </a> tags? Maybe I don't understand XML terminology well enough, but I kind of thought that adding an element woud mean doing something like this:

<a>Text text <b>Footnote code</b><a>The new text</a></a>

In other words, how do I specify that the child I want to add to the original <a> element is just a text element?

Or maybe you should review the "local typographical rules" to see if maybe the footnote does not need to be placed before punctuation when no text follows. Frankly, I think the "rule" you stated is suspect -- having footnotes after punctuation seems like a common practice.)

This is all in French, and French typography rules want the footnote reference before the punctuation. This is a little-known rule, even amongst French authors, which is partly why I'm building this filter.

In any case, are you sure that looking just for final period or comma is sufficient? What about question/ exclamation marks, quotation marks, parens, and any combination thereof?

Exactly. This is phase one of figuring out how to do this. Next comes all the fun dealing with the different punctuation possibilities. Quotations marks (»), question marks, colons, semicolons, and exclamation points all must be preceeded by a non-breaking space.

sub jf { print substr($_[0], -1); jf( substr($_[0], 0, length($_[0])-1)) if length $_[0] > 1; } jf('gro.alubaf@yehaf');

In reply to Re^2: Moving a tag within text with XML::Twig by skillet-thief
in thread Moving a tag within text with XML::Twig by skillet-thief

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.