"James Edward Gray II" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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? >
Along with Rob's suggestions, dbm files are great for this sort of thing: [EMAIL PROTECTED] misc]$ cat dbmtest.pl use POSIX; use AnyDBM_File; use strict; tie( my %database, 'AnyDBM_File', 'data.db', O_RDWR|O_CREAT, 0644 ) or die("tie failed: $!"); $database{ counter }++; print( "$0 invoked $database{ counter } times\n" ); [EMAIL PROTECTED] misc]$ perl dbmtest.pl dbmtest.pl invoked 1 times [EMAIL PROTECTED] misc]$ perl dbmtest.pl dbmtest.pl invoked 2 times [EMAIL PROTECTED] misc]$ perl dbmtest.pl dbmtest.pl invoked 3 times [EMAIL PROTECTED] misc]$ perl dbmtest.pl dbmtest.pl invoked 4 times Purl turns dbm files into persistent hashes, so you can store all kinds of data in there and other than the tie(), they behave exactly like hashes. If simultaneous invocations are possible, check the docs about locking tied dbm files. Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]