I am trying to collect a group of data from text file base on a couple of checks. Example: I have a text file that searched multiple xml file and extracted the following tags.
<MS_1> <loc>c:\data\cat.xml</loc> <words>dog, cat, fish, bird</words> </MS_1> <MS_2> <loc>c:\data\cow.xml</loc> <words>dog, cat, fish, bird, cow, goat</words> </MS_2> <MS_3> <loc>c:\data\snake.xml</loc> <words>dog, cat, fish, bird, snake, orange</words> </MS_3>
What I am trying to do is to prompt the user to enter the name of the animal to find. If the user enters snake for example, I want to return the entire content of <MS_3>..</MS_3> inculding the MS_ tags. I have tried the following code but I am getting nowhere. Could any monk kindly help me with this.
print ("Enter the word to search >> "); chomp ($word = <STDIN>); my $listen = 0; open(SEARCH, "<$kwords") while (<SEARCH>) { chomp; @array = (); foreach($_ =~ /\<MS_/){$listen++;} push (@array, $_) if /\<MS_$listen\>/../\<\/MS_$listen\>/; if ($_ =~ /$word/i) { print("@array[0..$#array]\n"); } }
Thanks,
Edman
In reply to Printing a Tag content by gzayzay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |