Hi,
I also believe that it is best to use a proper XML parser if you can, but I have encountered similar problems with non XML data, and then you do need to use regexes.
I think this is a nice workaround that will solve your problem (I hope)
use strict; use warnings; { my ($input_file) = @ARGV; open XML, $input_file or die; my $xml_data; ##Read the XML into xml_data while (my $line = <XML>){ $xml_data .= $line; } ##Parse xml_data while ($xml_data =~ /<Dataentry>(.*?)<\/Dataentry>/s){ ##Keep xml block to print if needed my $xml_block_to_print = $1; my $xml_block_to_parse = $xml_block_to_print; $xml_data = $'; ##Parse the xml block, and if we have a match, print! while ($xml_block_to_parse =~ /<Data>(.*?)<\/Data>/){ my $data = $1; $xml_block_to_parse = $'; if ($data eq 'bbbbbb'){ print "$xml_block_to_print\n"; last; } } } }
Please let me know if this works for you
mrguy

"Unix is user friendly - it's just a bit more choosy about who it's friends are."

In reply to Re: Match on line, read backwards to opening xml tag then forward to closing tag by mrguy123
in thread Match on line, read backwards to opening xml tag then forward to closing tag by shadowfox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.