i finally ended up with something similar...
print &popline("passcodes.txt",10,7); sub popline { my ($file, $lineswanted, $linelength) = @_; open DATA, "+< $file"; my @fileinfo = stat DATA; my %records = (); $records{filesize} = $fileinfo[7]; $records{wanted_bytes} = $lineswanted * $linelength; $records{readpoint} = $records{filesize} - $records{wanted_byt +es}; # seek (DATA, -$records{wanted_bytes},2); # reads from the end + of file, readpoint computation not necessary seek (DATA, $records{readpoint},0); # reads from beginn +ing, used b/c readpoint computation needed for truncate my @lines = <DATA>; truncate(DATA,$records{readpoint}); return @lines; }
i'll add in flocking etc tonight.
short of filling up a database w/20k possible keys + status tags, what i did was create a flat.txt of possible keys. this function is for 'activating' a key -- 50-100 will be pulled off the file, inserted into a db with a status flag (active/used), and merged w/documentation is this the most secure method? probably not. but if someone is going to hack my machine and grab the file -- well, i'm just going to assume that they're talented enough to hack into mysql and alter the db as they see fit.

In reply to Re: Re: popping or shifting a line off a file by nmerriweather
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.