Skip to content Skip to sidebar Skip to footer

Retrieve Value From A Form And Write To A File

i have a form named index.cgi and a configuration file named video.start After the user select from the drop down menu and press submit, the value will be read and write into

Solution 1:

The biggest trick to this is that you need to flock your files before editing them so there isn't a race condition.

use strict;
use warnings;
use autodie;

use Fcntl qw(:flock);

openmy $fh, '<+', 'foobar.txt';
flock($fh, LOCK_EX) ordie"Cannot lock mailbox - $!\n";

After that, just read How do I change, delete, or insert a line in a file, or append to the beginning of a file?. I personally would go with Tie::File as I think that's probably the easiest way to edit a file in this context.

Post a Comment for "Retrieve Value From A Form And Write To A File"