in reply to Re^2: XML::Twig replace method behaving counter-intuitively
in thread XML::Twig replace method behaving counter-intuitively

The next version of XML::Twig will actually cut the element if hasn't been cut before. That's easier than changing the docs ;--)

And I am still not at 100%, I meant prev_sibling, not previous, my bad.

  • Comment on Re^3: XML::Twig replace method behaving counter-intuitively

Replies are listed 'Best First'.
Re^4: XML::Twig replace method behaving counter-intuitively
by Human (Initiate) on Dec 04, 2007 at 20:58 UTC
    For anyone keeping score, here is the final subroutune:
    # As each tweak tag is processed, this subroutine is called. Here we +will # see if any previous tweak tag had the same name attribute. If so, w +e will # replace the previous tweak tag with this new tweak tag's contents. sub pruner { my ($twig, $this_tweak) = @_; my $tweak_name = $this_tweak->att('name'); my $previous_tweak = $this_tweak->prev_sibling( qq{tweak[\@name="$ +tweak_name"]}); # If the tweak's name is found elsewhere, replace the first # instance with the latest one, then delete the latest one. if ($previous_tweak) { print "\tReplacing\n\t\t" if $debug; $previous_tweak->print if $debug; print "\n\twith\n\t\t" if $debug; $this_tweak->print if $debug; print "\n" if $debug; $this_tweak->cut; $this_tweak->replace($previous_tweak); } }
Re^4: XML::Twig replace method behaving counter-intuitively
by Human (Initiate) on Dec 04, 2007 at 20:31 UTC
    It's working beautifully now, thank you very much!

    Get well soon :)