in reply to To find the last occurence and replace in perl

Sure, thats easy, write some code, use XML::LibXML with tools like xpather.pl/htmltreexpather.pl which can give you paths to start with, and all the links here Re: Retrieve select information from HTML, they're examples(for tree-xpath and others)/walkthroughs/tutorials ...
  • Comment on Re: To find the last occurence and replace in perl

Replies are listed 'Best First'.
Re^2: To find the last occurence and replace in perl
by Anonymous Monk on Dec 30, 2014 at 09:03 UTC
    #!/usr/bin/perl -- use strict; use warnings; use XML::LibXML 1.70; ## for load_html/load_xml/location my $xml = q{<contrib-group> <contrib contrib-type="author"> . some code . <x>, </x></contrib> <contrib contrib-type="author"> . some code . <x>, </x></contrib> <contrib contrib-type="author"> . some code . <x> and </x></contrib> <contrib contrib-type="author"> . some code . </contrib> </contrib-group> }; my $dom = XML::LibXML->new(qw/ recover 2 /)->load_xml( #~ location => $filepath_or_http, string => $xml, ); print $dom->find(q{ //contrib/x[ contains( . , ' and ' ) ] })-> +shift->nodePath, "\n"; if( my $cx = $dom->findnodes(q{ //contrib/x })->pop ){ print $cx->nodePath, "\n"; print "$cx\n"; my $tx = $cx->textContent; $tx =~ s/ and / , /; $cx->removeChildNodes; $cx->appendText( $tx ); print "$cx\n\n\n"; } print "$dom\n"; __END__ /contrib-group/contrib[3]/x /contrib-group/contrib[3]/x <x> and </x> <x> , </x>
    A reply falls below the community's threshold of quality. You may see it by logging in.