purple :2:blue :1:red :2 #### #!/usr/bin/perl -w use strict; #use Fcntl ':flock'; # import LOCK_* constants use CGI; use CGI::Carp qw/fatalsToBrowser /; my $q = CGI->new(); ######### CONFIG ############# my $results_file ="c:\\windows\\desktop\\survey.poll"; my (%data, @file); ############################## print "Color choice: red, blue, or purple?\n"; my $input = ; chomp $input; get_data(); exit; sub get_data { if (-e $results_file){ open (FH, "+< $results_file") or die "where's the damn file? : $!"; } else { open (FH, "> $results_file") or die "where's the damn file? : $!"; } #flock (FH,LOCK_EX) or die "Couldn't flock: $!"; $_ = ; chomp; if ($_) { my @file= split(/:/); %data = @file; } $data{$input}++; seek FH, 0, 0; truncate (FH,0) or die "Can't truncate: $!"; @file = join(":",%data); print FH @file; #flock(FH,LOCK_UN); #unlock the file close FH or die "close damn you : $!"; }