sara2005 has asked for the wisdom of the Perl Monks concerning the following question:

I am using Perl/CGI in Apache to create some dynamic web pages by reading data from flat files.. Below is a problem I am facing and would appreciate any help from the experts..

I read a data file as shown below and store the contents in an Array of Hashes (AoH)

File1: --------------------- Page = 1 <Start> VarName = name1 Value = value1 Min = min1 Max = max1 <End> <Start> VarName = name2 Value = value2 Min = min2 <End> etc.. etc. Page = 2 <Start> VarName = nam1 Value = val1 <End> <Start> VarName = nam2 Value = val2 Min = mn2 <End> --------------

Note that each hash has been initialized with a standard set of 'key's and after reading the file, only the available keys are populated with a value. after I am done reading the file in an AoH, this is how it looks using Data::Dumper.

[ { 'PageNum'=>1, 'VarName' => 'name1', 'Value' => ' value1', 'Min' => ' min1', 'Max' => ' max1', 'Mod' => ' ' }, { 'PageNum'=>1, 'VarName' => 'name2', 'Value' => ' value2', 'Min' => ' min2', 'Max' => ' ', 'Mod' => ' ' }, etc.. etc.. { 'PageNum'=>2, 'VarName' => 'nam1', 'Value' => ' val1', 'Min' => ' ', 'Max' => ' ', 'Mod' => ' ' }, { 'PageNum'=>2, 'VarName' => 'nam2', 'Value' => ' val2', 'Min' => ' mn2', 'Max' => ' ', 'Mod' => ' ' }, etc..etc.. ]

Now, my CGI code prints out a multipage html page in the following format using the AoH:-

------------- <html><head><title>test</title></head> <body bgcolor="white"> <table border="0"><tr><td><b>Page num:</b></td> <td><select name="page +" size="1" onchange="submitform('Go')"> <option value="1">1</option> <option value="2">2</option> </select> </td> </tr> </table><br /> <table cellpadding="2" id="panel" cellspacing="0" border="1"> <tr align="LEFT"> <th bgcolor="cyan">Variable</th> <th bgcolor="cyan">Min value</th> <th bgcolor="cyan">Value</th> <th bgcolor="cyan">Max Value</th> </tr> <tr valign="TOP" align="LEFT"> <td ><a>name1</a></td> <td ><input type="hidden" name="min1" value="min1" /><a>min1 </a></td> + <td ><input type="input" name="value1" value="value1" /><a></a></td> <td ><input type="hidden" name="max1" value="max1" /><a>max1</a></td> </tr> <tr valign="TOP" align="LEFT"> <td ><a>name2</a></td> <td ><input type="hidden" name="min2" value="min2" /><a>min2 </a></td> + <td ><input type="input" name="value2" value="value2" /><a></a></td> <td ><input type="hidden" name="" value="" /><a></a></td> </tr> </table> </form><center /> </body> </html> --------

The idea is , no matter how many pages are there in the flat file, the inputs pertaining to a selected 'page num' alone will be shown in a page. When the user selects a different page, those inputs listed for the selected page will be shown.

Now, I have a problem when I want to edit a given variable in a given page. The requirement is :-

1) I need to keep track of all the variables that have changed (possibly in the same flat file format) and

2) display the modified variable values, if the user selects a page he had modified few minutes back.

First, I thought about using session management but it only saves the variables and values for a given page (in var=val format). If I have 10 or more pages, it might get cumbersome to manage in this method.

Second, I thought about passing the array of hashes from one page to another but it seems unlikely (not sure though!!! any suggestion on this??)

Finally, I have decided to make a copy of the original flat file and read from the 'copy' to create the input pages. Now, when a value is edited in a given page, I am planning to use a perl script to open the 'copy', go to the appropriate variable that has to be modified and change the value. In this way, I can keep modifying the values and at the same time display the values to the user, if he returns back to the same page within few minutes. Also, by doing a diff with the original, I will be able to get the list of variables that have changed.

Is this is a good approach? Is there any other method that would simplify this task?

Please provide your valuable comments.