# # @(#) survey.pl 1.0 03/13/04 # # Copyright (c) 2004 # Ali Onur Cinar &060;cinar(a)zdo.com&062; # # License: # # Permission to use, copy, modify, and distribute this software and its # documentation for non-commercial use and without fee is hereby granted # provided that the above copyright notice appear in all copies and that # both the copyright notice and this permission notice and warranty # disclaimer appear in supporting documentation, and that the name of # Ali Onur Cinar not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior permission. # use Win32::OLE; use Cwd; @questions = # questions ( { 'name' => 'Question 1', # question's name 'maxAnswers' => 1, # for single question 'noAnswers' => 0, 'choices' => # answer choices { 'Q1_A' => 0, 'Q1_B' => 0 } }, { 'name' => 'Question 2', 'maxAnswers' => 2, 'noAnswers' => 0, 'choices' => { 'Q2_A' => 0, 'Q2_B' => 0, 'Q2_C' => 0, 'Q2_D' => 0 } } ); $cwd = getcwd(); # current directory $cwd =~ s!/!\\\\!g; # path separators for $file (glob("*.doc")) # for each survey { $doc = Win32::OLE->GetObject("$cwd\\$file") # open survey file or die Win32::OLE->LastError(); for $question (@questions) # for each question { $nAnswers = 0; # init num of answers for $choice (keys(%{$question->{'choices'}})) # go trough answers { if ($doc->FormFields($choice)->Result eq 1) # if choice is selected { $question->{'choices'}->{$choice}++; # add it to count $nAnswers++; # num of answers } last if $nAnswers ge $question->{'maxAnswers'}; # stop if max answers } # reached if ($nAnswers eq 0) # if no answer found { # increment the no $question->{'noAnswers'}++; # answer count } } $doc->close(); # close survey file } for $question (@questions) # for each question { print $question->{'name'}."\n"; # question name for $choice (keys(%{$question->{'choices'}})) # for each choice { printf(" %-15s\t%-5d\n", $choice, # answer count $question->{'choices'}->{$choice}); } printf(" %-15s\t%-5d\n\n", "Not Answered", # no answer count $question->{'noAnswers'}); }