in reply to Dear fellow monks, I need help in regex
I recommend using the Tie::File CPAN module since otherwise you have to create a temporary file, copy the original file to it with your changes, and then rename the temporary file to replace the original file.
You may also want to consider using a database (such as DBD::SQLite) instead of a plain text file depending on how many monks you have and how often you will be updating their meal choices. Manipulating plain text files in this fashion doesn't scale well.use Tie::File; sub loadmeal { my($meal) = $_[0]; tie @meals, 'Tie::File', "/home/shaolin/public_html/monkmeals.txt" or +die ...; for (@meals) { s/leeming=.*/leeming=$meal/ } untie @meals;
|
|---|