in reply to How to overwrite one variable in an array?
The statement: open (DAT,">$RECORD/$form{'User'}"); will overwrite a file in the directory data.db, whose name is the value input by the user1, but I don't think that's what you intended. My guess is you want to open the file data.db, then find the record corresponding to the input value.
If so, and you're trying to use a flat file, consider using fixed-size records. That way, you can open the file and seek to particular records either by searching sequentially or by saving the offsets of particular records.
But the operations you're describing (find a record, change its value, write it back) are much more easily accomplished with a relational database system. Otherwise you'll be re-creating index-sequential systems that were mostly abandoned years ago (for many reasons, inflexibility being one of the primary ones). Then your sub may simply reduce to two SQL statements: fetch the data, update the data.
If you don't have a database already, MySQL is an easy place to start. You can find many documents and examples for setting it up.
HTH
1BTW, creating files whose names come from user input is a bad practice in and of itself....
|
|---|