Hello all,

I've been reading the PM write-ups on Tie::File (All hail Dominus!), and they've been great, but I still can't figure out how to conditionally insert lines into a file if they don't exist.

The script I'm writing is supposed to look for server entries, placing them at the end of the file if they're absent or replacing them if incorrect. I've got the replacing part going great. That was easy. However, if the entries aren't present, I need to add them.

How should I go about checking for these entries? Let's say they should look something like this:

server1=myhost1.mydomain.com
server2=myhost2.mydomain.com

I'm sure there's an answer that's stupidly simple and I'm just not seeing it. I really can't make up my mind whether I should be using an array function or if I should be using something from Tie::File itself. Or perhaps there's an entirely different method of which I'm not even aware.

Thanks for any help you can give.

Dev Goddess
Developer / Analyst / Criminal Mastermind

"Size doesn't matter. It's all about speed and performance."


In reply to Inserting lines in a file with Tie::File if lines don't exist by devgoddess

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.