James Edward Gray II wrote:
>
> Okay, I have a very simple script that needs to keep track of a counter
> between runs (the only piece of persistent information).  I thought it
> might be simple to just store this counter after __DATA__, instead of
> creating an entire config file to hold one number.  That leads to my
> questions.
>
> First, is this logic okay?  Any big reasons I shouldn't do this?
>
> Second, HOW do I do this?  I'm guessing I somehow need to activate
> inplace editing or something similar, then use something like
> s/^Document_Number:(\d+)$/$1 + 1/e.  Do I need to reopen DATA
> differently first?
>
> Third, I may need to pull the number more than once during execution.
> Do I use a seek(DATA, 0, 0) to go back?  Won't that actually put me at
> the beginning of my whole script?  Is there a simple way I can just go
> back to __DATA__?
>
> And Finally, I need to protect against multiple executions changing it
> at once.  I just flock() my script while I'm changing it to handle
> that, right?
>
> Thanks in advance for any advice you can share.  I've just never tried
> anything like this before.

Hi James.

My advice is simply to forget it. Open an 'entire' config file with a
single record containing a single number. The DATA file handle is opened
read-only and, while it's possible to reopen it for read/write, you would
be writing a self-modifying program which is frowned upon in all circles
except AI. For a production program I would make it nice by writing a
comment header saying what the config file is for, and a label for the
number in case you want to add further persistent values.

HTH,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to