#!/usr/bin/perl -wT # myscript.cgi # always use strict use strict; # use CGI.pm to process CGI input use CGI; my $q = CGI->new; # use Fcntl to allow file locking use Fcntl qw(:DEFAULT :flock); # configuration variables my $path = '/usr/your/home/logs'; my $name_file = 'names.txt'; my $email_file = 'emails.txt'; # assign form data to variables my $name = $q->param('name'); my $email = $q->param('email'); # print our data to a file print_to_file("$path/$name_file", $name); print_to_file("$path/$email_file", $email); # print data to file print_to_file { my $file = shift; my $data = shift; open (FILE, ">>$file") || die "Unable to open $file for appending: $!"; flock (FILE, LOCK_EX) || die "Can't get an exclusive lock on $file: $!"; print FILE "$data\n"; close FILE; }