I am trying to play around with arrays and I am having a few problems. Could any monk kindly help me with the following?
I have a document with several tags:
<tag1> <fast> Slow down boy!!!<p> </fast> <slow> Increase your speed.<p> </slow> </tag1> <p> <tag2> <fast> Slow down boy!! BIG HEAD!<p> </fast> <slow> Increase your speed.<p> </slow> </tag2>
My task is to place the entire content of tag1 into an array. After placing the content into the array, I want to search the array to see if it contains e.g. “BIG HEAD” if not destroy the content and move tag2 content into the array and search for “BIG HEAD” in the content of tag2. If found, print the entire content of tag2, and so move onward i.e. tag(1)..tag(n). For each tag that contains the search item, print out the entire tag and move to the next tag. Also, when moving on, destroy the content of the array before importing the content of the next tag.
My code is as follows, but it does not work as desired.
my $count = 0; Open ( FILE, $reader) || die “Cannot open, $!\n”; while (<FILE>) { Chomp; foreach($_ =~ /\<tag\>/){$count++;} print $_, “\n” if /\<tag$count\>/…/\<\/tag$count\>/; @ray = (); push(@ray, /\<tag$count\>/…/\<\/tag$count\>/); }
The above code is what I have attempted to load the content of the tags onto “ray” but it is not working. Could a monk kindly help me with this task?
Thanks,
Edman
In reply to Population of an array by gzayzay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |