Mailing list

Please fill out this form to subscribe

Name:

Email:

#### #!/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; } #### #!/usr/bin/perl -wT # myprint.cgi # always use strict use strict; # configuration variables my $path = '/usr/your/home/logs'; my $name_file = 'names.txt'; # print the header line, and html stuff print < Names

Names list

HTML # get data from a file into an array and print it my @file_data = get_file_data("$path/$name_file"); print "

Name: $_\n

" for @file_data; # finish neatly print"\n\n" # get data from a file get_file_data { my $file = shift; open (FILE, "<$file") || die "Unable to read from $file: $!"; my @data = ; close FILE; return @data; }