Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Match on line, read backwards to opening xml tag then forward to closing tag

by Anonymous Monk
on Nov 14, 2011 at 17:24 UTC ( [id://937993]=note: print w/replies, xml ) Need Help??


in reply to Match on line, read backwards to opening xml tag then forward to closing tag

use Modern::Perl; $_ = ' <Dataentry> <Data>aaaaaa</Data> <Data>aaaaaa</Data> <Data>aaaaaa</Data> </Dataentry> <Dataentry> <Data>aaaaaa</Data> <Data>aaaaaa</Data> <Data>aaaaaa</Data> </Dataentry> <Dataentry> <Data>aaaaaa</Data> <Data>bbbbbb</Data> <Data>aaaaaa</Data> </Dataentry> <Dataentry> <Data>aaaaaa</Data> <Data>aaaaaa</Data> <Data>aaaaaa</Data> </DataEntry>'; my ($f,@l);my $d='Dataentry';sub p { push (@l,"$_[0]\n");$f ||= $_[0]=~ m@>bbbbbb<@s;@l = '' if ($_[0]=~ m@</$d>@s);if (($_[0]=~ m@<$d>@s)&&($f)) {pop @l;say "<$d>";print reverse @l; say "</$d>";@l = '';$f = 0;}} p $_ for reverse split '\n';
Who do __YOU__ know that writes regex's like that?
  • Comment on Re: Match on line, read backwards to opening xml tag then forward to closing tag
  • Download Code

Replies are listed 'Best First'.
Re^2: Match on line, read backwards to opening xml tag then forward to closing tag
by Anonymous Monk on Nov 14, 2011 at 23:08 UTC
    my ($flag,@lines); my $d='Dataentry'; sub process { push (@lines,"$_[0]\n"); $flag ||= $_[0]=~ m@>bbbbbb<@s; @l ='' if ($_[0]=~m@</$d>@s); if (($_[0]=~ m@<$d>@s)&&($flag)) { pop @lines; say "<$d>"; print reverse @lines; say "</$d>"; @lines = ''; $flag = 0; } } process $_ for reverse split '\n';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://937993]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found