in reply to saving a random number while generating a new one
What you're encountering is a fundamental misunderstanding of how CGI scripts work. When your user is interacting with your HTML page and CGI script, here's what's happening:
Note that your script is running again and again as if it had never run before. It has no state, and the code you've shown has no way of retaining state. As you mention, you can use a file to save previous runs. As an alternative, what you might do is to use CGI::Session to have a session for the user that retains all the runs that they've made. If you don't want something that heavy, then you could use DBI along with DBD::SQLite to have a SQLite database (which is a flat file, ultimately) for your data storage. If you don't want DBD::SQLite, you could use a full blown database engine such as DBD::mysql or DBD::Pg.
Based on your code, it seems that you are not yet familiar with HTML/CGI idioms or syntax, so I would actually pursue a simple text file (Perl excels at reading and parsing simple text files) as your data collection mechanism
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: saving a random number while generating a new one
by raybies (Chaplain) on Mar 30, 2011 at 15:13 UTC |