Only problem: It fills every file with the stinkin here document. over and over.

Yeah, it does. That's what your continue block does, if the conditional is true. That's what your else block does, if the conditional is not true. You need to stop commenting and uncommenting code and randomly adding and moving around code, because you're just making a mess and confusing yourself.

Here is your first problem:

} else { ($line =~ m/'syslogd'\)/); my $newline = $. + 3; $newline = $bgs; print OUT $newline; next; }</c>

This block only executes if the current line does not contain bgs. That's probably most lines of the file.

The regular expression does nothing. It's dead code. Delete it.

The next line declares the variable $newline and assigns it a value. This is nearly dead code, because the subsequent line overwrites that value with the heredoc, which gets printed in the next line. Control flow then skips to the continue block, which prints the current line.

You're not going to get this to work until you sit down, write out what you want to accomplish, list the necessary steps in order, and then translate that to code. Please do that; you'll save yourself a lot of time and trouble.


In reply to Re: if or die! by chromatic
in thread if or die! by wcj75019

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.