Hi Monks,

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.