Greetings Monks!

I am trying to find out how to dump arrayB into arrayA as the (new) last element. Kind of like push(), except that rather than adding the elements of arrayB at the end of arrayA as several more elements, you get all of arrayB as the last element of arrayA.

A short (and simplified) explanation of what I'm trying to do:

User supplies a filename, which contains a variable number of text blocks. User then supplies a variable number of strings. Each block of text is read in, piecemeal, and searched for each string. Each pass through saves the position of each match to a string into an array (arrayB). This array of matches to the first string becomes the first element of arrayA. The search is repeated for the second string (a new arrayB), and this array becomes the second element of arrayA, and so on for the number of strings the user desires. Once the first text block has been thoroughly search, arrayA now gets dumped into the first element of arrayC. Then, we progress on to the second text block, and so on from there.

Ideally, I would then format each text block to highlight each string-match in a particular color, based on the position of hits stored in each ArrayB, corresponding to the particular string matched stored in each ArrayA, corresponding to the text block the hits are found in (the position in ArrayC.

So, the length of ArrayC is a variable dictated by the contents of a user input file, the length of each element of ArrayC is ArrayA, which is dictated by the number of strings to be searched for, again dictated by the user, and the position of each of the matches to each string is uncovered by m//, and stored in ArrayB

I hope that makes sense to someone other than me.

Any advice would be greatly appreciated.

TIA,
Matt


In reply to appending and array into last element of an array? by mdunnbass

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.