Leaving the security aspects aside, let me say a few things.

I assume you are going to run this program relatively often, other wise you should be spending your time on other things than efficiency. However, if this is going to be run often, you want to avoid deleting parts of the file as much as possible. I do not recommend Tie::File solutions, as they will modify the file.

Instead, I recommend changing the content of the file. Instead of having 8 characters on a line, have nine. The ninth character will indicate whether a record has been used or not. Say you use a ! and a * for the ninth character. Initially, all records will have a !, signalling it's unused. Once you use a record, flip the ninth character to be a *.

You do have to flock your file though, otherwise two instances of your program could hand out the same password. And that's something you want to avoid. Also make sure that you first mark a record for deletion before you actually hand it out. Because in that case, the worst that can happen is some records will be marked as 'in use' while they aren't. Otherwise, an unfortunate crash or termination of your program might cause a record to be reused. (Too bad Perl flock() can only lock entire files, not regions).

I do think however that you will be better off not using a file based system. Using a good database will solve many of your problems with concurrent access and efficient deletion of records.

Abigail


In reply to Re: popping or shifting a line off a file by Abigail-II
in thread popping or shifting a line off a file by nmerriweather

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.