in reply to How to find the value of the first and last occurence of an XML node?
The fact that something is one line is not relevant. Consider this document as a single line-
$the_oxford_english_dictionary =~ s/\r?\n/ /g;It wouldn't make it any easier to parse. In your case, I'm guessing you're resisting a parser because your XML is invalid (aka, garbage). A parser *is* the way to go and if you provide real sample XML you'll probably get help with it. That said, this might do what you want without a parser-
my $doc = '<?xml version="1.0"?><root><a:b>one</a:b><a:b>two</a:b></ro +ot>'; my $last = [ $doc =~ /a:b>([^<]+)/g ]->[-1]; print $last, $/;
It won't be reliable or flexible though. :|
|
|---|