in reply to Re^2: Match on line, read backwards to opening xml tag then forward to closing tag
in thread Match on line, read backwards to opening xml tag then forward to closing tag
Probably you changed my script because I used "<DataStart>" and "<DataEnd>" instead of the correct "<Dataentry>" and "</Dataentry>" in my regexes. Sorry about that mistake but apart from that my script is working (I tested it just now to be sure). Just use the right strings in the regexes and the script will work, even with the new data you provided.
my @cache; my $found=0; while (<$file>) { if ( /stringtobefound/) { $found++; } if (/<start fo record>/) { @cache=(); } push(@cache, $_); # print "-----------\nFound is $found, Cache is\n".@cache."----------- +---"; if (/<\/end of record>/ and $found) { print @cache; $found=0; } }
A tip on general debugging: If something doesn't work, print out important variables and watch what your script is doing and find the first place where it does something different than it should. See the comment line for an example, with that you can see if the cache works or not
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Match on line, read backwards to opening xml tag then forward to closing tag
by shadowfox (Beadle) on Nov 15, 2011 at 13:49 UTC |