I wrote it several different ways, and either it prints every <DataRecord> or only filtered <Data> lines, neither is what I need. I want it to print the entire <DataRecord> if that record matches on the second pattern. Clearly I'm doing it wrong but I'm not seeing what, so I assume its glaringly obvious.<DataStore> <DataRecord> <Data>123456</Data> <Data2>654321</Data2> <Data>123456</Data> </DataRecord> <DataRecord> <Data>123456</Data> <Data>123456</Data> <Data2>123456</Data2> <Data>1234/3456</Data> <Data>123456</Data> <Data>1234/3456</Data> <Data3>123456</Data3> <Data>123456</Data> </DataRecord> <DataRecord> <Data>123456</Data> <Data>123456</Data> <Data5>123456</Data5> </DataRecord> </DataStore> # From that I want it to loop through and store each <DataRecord> ... +</DataRecord> # From then, if it matches on 4 digits followed by a forward slash I # want it to output the whole <DataRecord> to screen, not just the mat +ched lines from second filter. # For that, I've tried this example open(FILE, "< $FILE") or die "ERROR: $!"; while (<>) { if (/<DataRecord>/ ... /<\/DataRecord>/) { @cache=(); } push(@cache, $_); if (m/<Data>\d{4}\//){ print @cache; } } close (FILE); # The output of that is <Data>1234/3456</Data> <Data>1234/3456</Data> # where I would prefer to see <Data>123456</Data> <Data>123456</Data> <Data2>123456</Data2> <Data>1234/3456</Data> <Data>123456</Data> <Data>1234/3456</Data> <Data3>123456</Data3> <Data>123456</Data>
In reply to Re^2: Match on line, read backwards to opening xml tag then forward to closing tag
by shadowfox
in thread Match on line, read backwards to opening xml tag then forward to closing tag
by shadowfox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |