Resolution:

Below is the tested and working code (thanks guys!)

Note the newline chars (\n), those are required to tell Tie::File that these will be new lines and therefore new records in the array.

Even though i'm fooling with @array[$i + n] here, there's no chance of running off the end of the array because the test will fail negative before any action is taken on non-existant elements beyond the last record in the array.

The suggestions about HTML::Parser and so forth are well recieved, but since all i'm doing here is *generating* the html snippets, i don't think the Parser is really the right thing.

### Update the main threads file tie @threads, 'Tie::File', $main_threads_file or syslog('err', "update +_threads couldn't open file: $main_threads_file"); if ($thread == $msg_id) { # put it right at the top, it's a new thread unshift @threads, $link; } else { for my $i (0 .. $#threads) { if ($threads[$i] =~ $parent) { if ($threads[$i+1] eq "<ul type=\"disc\">") { # insert $link after the next element (after the <ul>) $threads[$i+1] .= "\n$link"; } else { # insert three new lines/records after the parent $threads[$i] .= "\n<ul type=\"disc\">\n$link\n</ul>\n" +; } last; } } } untie @threads;

Anyhow, thanks again for everyone's help! I hope this thread is useful to someone, someday.

Cheers!
914


In reply to Re: Conditonal insert into Array? (Tie::File) by u914
in thread Conditonal insert into Array? (Tie::File) by u914

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.