#!/usr/bin/perl # consent.cgi use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Fcntl ':flock'; use POSIX; #VARIABLES my $sys_time = POSIX::strftime("%D %T", localtime); my $data_path = "/home/account/cgi-bin/asewk"; my $jump_url = "http://mysite.com/ase-workkeys/consent-confirm.html"; my ($which_form, $consent, $user_name, $company, $user_email, @flatfields, $flatfile); #SCRIPT &setValues; &writeCSVfile($which_form, $flatfile); print redirect($jump_url); exit; #SUBROUTINES sub setValues { #get values from form $which_form = param('which_form'); $consent = param('consent'); $user_name = param('name'); $company = param('company'); $user_email = param('email'); #build line for csv flatfile @flatfields = ("$sys_time", "$consent", "$user_name", "$company", "$user_email"); $flatfile = join(",", map { local $_ = $_; s/"/""/g; qq("$_") } @flatfields); } sub writeCSVfile { my($filename, $linename) = @_; #name subroutine variables my $log_file = "$data_path/$filename\.csv"; open (LO, ">>$log_file") or die "Could not open $log_file: $!"; flock LO, LOCK_EX; #exclusive lock print LO "$linename\n"; close LO; }