I wouldn't store it right in the script for
these reasons at least:
- One day you may need the counter in some other
programs, and accessing it could be harder than it needs
to be
- There are several good reasons for not altering
production scripts. Think about the consequencies of
restoring the script from an old backup for example, the counter would be
restored to an old, incosistent value
- It makes debugging and testing unnecessarily
complicated: unless you
take precautions (e.g. a production counter and a test
counter on different sections after the end of the script)
- You may not have write permissions on the script at all,
which is probably going to be the case, or the script itself
might be on a read-only partition (quite an interesting
security measure, especially when we're talking about
finance and transactional computing)
The most reasonable choice is probably following the KISS
(Keep It Simple, Stupid) principle, storing the counter
in a plaintext (easy debugging, no libraries required) file where
locking prevents messy race contitions or nasty inconsistencies.
Naturally the file name shouldn't be hardcoded in the source.
-- TMTOWTDI