in reply to help need when processing xml using perl

CountZero's solution is of course far more elegant. I thought I'd see if I could code a filter using just regex, however:

use strict; use warnings; my ($xml, $content, @xml); $xml = join '', <DATA>; while ($xml =~ m/(<details>.*?<\/details>)/sg) { $content = $1; next if $content !~ /<address>.+?<\/address>/; push @xml, $content; } $xml = "<specification>\n" . join("\n", map { " $_" } @xml) . "\n</specification>"; print $xml; __DATA__ <specification> <details> <name>johan</name> <address>Langgt 23</address> ---more info--- </details> <details> <name>venu</name> <address>storgatan 27</address> ---more info--- </details> <details> <name>kent</name> <address>nygatan 46</address> ---more info---- </details> <details> <name>johan</name> <branch>ece</branch> ---more info-- </details> </specification>

Replies are listed 'Best First'.
Re^2: help need when processing xml using perl
by veerubiji (Sexton) on Nov 29, 2011 at 08:59 UTC

    Thanks for your solution.but I don't know how to vote you.

      You have to get to level 2 or 3 before you start getting votes, and until then you won't see the vote option.