I guess your post is a continuation of find the xml files. Why didn't you tell us that?
You have all parts ready, but you will have to combine them differently. The problem in your code is that you read your file line by line in the
while (<IN>) {
...
}
loop, and I assume that your XML file contains the empty
book tag and
Sydney on two different lines.
There are two approaches to solve this:
- For large files: Read the file line by line and remember for each file whether you've seen an empty book tag, and also remember whether you've seen Sydney. After you've read through the file, look whether you've seen both.
- For small files: Read the file as a whole into one scalar and check whether the scalar contains both, the book tag and Sydney.
- (There's always a third option) Use a proper XML parser, and XPath queries to check whether there are //book[text()=""] tags and //text()="Sydney" nodes. This is the recommended and least fragile solution.
For the "case insensitive" part, see perlre.