Hi, mirod! No apology for being sick is necessary. Thanks very much for replying.

The cut did the trick! :) FYI, the thing that threw me was the difference in the wording of the documentation for the paste and replace methods, as shown on CPAN. The paste method makes it clear that you can only paste previously-cut elements (of course), but the replace method says "Sometimes it is just not possible tocut[sic] an element then paste another in its place, so replace comes in handy." I interpreted this to mean that replace was analogous to cut and paste, when you wanted to paste over another element. If I may recommend a simple change to the line that precedes it, to give it context: "Replaces an element in the tree." -> "Replaces an element in the tree with a previously cut element." (or whatever the general case is)

Thanks for the array syntax pointer - it's a bad habit of mine, and I'll debug with -w from now on :)

I completely missed the information that the current twig is passed into the subroutine, but I'm glad I know now.

I did run into a problem executing the new code that looks for the previous matching element: $this_tweak->previous_sibling( qq{tweak[\@name="$tweak_name"]})

$ ./twig_replace_test.pl Can't locate object method "previous_sibling" via package "XML::Twig:: +Elt" at ./twig_replace_test.pl line 14.
Do I need to define that method myself?

In reply to Re^2: XML::Twig replace method behaving counter-intuitively by Anonymous Monk
in thread XML::Twig replace method behaving counter-intuitively by Human

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.