The scripts below were written by William Schmidt to 
support use of factorWiz and surveyWiz for Mac.


PERL script for coding and saving data to Mac OS X

How to use: 1. Perl is already installed in Mac OS X. 2. You may want or need to edit the script by replacing: (i) URL to redirect users after accepting data in line 2 (optional--this is the URL of the "thank you" message) (ii) the path to the directory where your data files are to be stored in line 3; note the trailing slash after the directory name. Be sure to adjust Step 3 accordingly. (iii) If OS X changes how Perl is configured in the distribution, you might need to change the first line to specify the path to Perl. 3. Create a folder on your Hard Drive named "DataFiles". Select this file, and choose "Get Info" by clicking the Apple Key and letter "i" at the same time. Click the pop down list and select "privileges". Set the first two to "Read and Write" and set the third to "Write Only". That is "drop box". (You must be an administrator on your computer to do this.) 4. Save the script as save_data.pl. This MUST be saved as a Unix Text file ONLY. You can use BBEdit Lite to do this. 5. Place your script in the following directory. Start on The Macintosh Hard Drive, and open the folder "Library". Now Open "WebServer". Next open "CGI-Executables" and put the file, save_data.pl in this folder. 6. Now you need to open the Terminal. Open the "Applications" Folder and look in the "Utilities" Folder. Double click the Terminal and a window will open. This is an old-fashioned computer device and you must enter commands one at a time, and be very careful that everything is exactly right before you hit the return key. 7. At the terminal prompt, type the following command: chmod ugo+rwx /Library/WebServer/CGI-Executables/save_data.pl Before you hit return, check that everything, including spaces and capitalization as well as spelling is exactly right. There is a space after chmod, and there is a space after rwx. When everything is correct, hit return. Nothing particular happens and a new prompt appears. You should now be able to access this script from the Web browser. 8. You can now test the script by typing the following URL in your Web browser: http://localhost/cgi-bin/save_data.pl You should be redirected to the file on the Web specified by line two of the script. 9. Next, find the <FORM> tag in the HTML file you made with SurveyWiz or FactorWiz. This reads as follows: <FORM METHOD='post' ACTION='http://psych.fullerton.edu/cgi-win/polyform.exe/generic'> Change it to the following: <FORM METHOD='post' ACTION='http://localhost/cgi-bin/save_data.pl'> 10. Save your HTML files, including the one you made in No. 10 in the following folder on your Mac. Open Library, Open WebServer, and put your HTML documents in the folder named "Documents". To see your Web file, type the following URL in the browser: http://localhost/filename.htm (You can also put your HTML files in the following folder: Open the Macintosh Hard Drive, Open Users, Select your Username, and open the "Sites" folder. You can put your HTML files here. To see your Web file, named filename.htm with this method, type the following URL in your browser: http://localhost/~username/filename.htm 11. Fill out the survey and click the submit button. You should be forwarded to the "thank you" page, and a file will appear in the directory DataFiles containing your data, named, shortName.data, where shortName is the name you typed for the shortName in surveyWiz or FactorWiz. 12. From another computer, a person would need to know your IP address or your URL name to reach your files. If you can acquire a fixed IP from your campus network, you can be assigned a domain name. To Contact William Schmidt: William C. Schmidt Dept. of Psychology Park Hall SUNY at Buffalo Buffalo, NY Warning: Open the text version and save it as "save_data.pl," as a UNIX TEXT FILE. Text File of save_data.txt ---------------------------PERL script below #!/usr/bin/perl $redirect_to = "http://psych.fullerton.edu/mbirnbaum/decisions/thanks.htm"; $path_to_datafile = "/DataFiles/"; use CGI; $query = new CGI; #timestamp the submission ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $mon++; #determine the data filename, open and dump data $filename = $query->param('00exp'); open(INFO, ">>$path_to_datafile/$filename.data"); foreach $key (sort($query->param)) { $value = $query->param($key); #filter out "'s and ,'s $value =~ s/\"/\'/g; $value =~ s/,/ /g; if ($value !~ /^pf/) { print INFO "\"$value\", "; } else { # filter out items that need to be expanded at submission time pf* if ($value =~ /^pfDate/) { print INFO "\"$mon/$mday/$year\", "; } if ($value =~ /^pfTime/) { print INFO "\"$hour:$min:$sec\", "; } if ($value =~ /^pfRemote/) { print INFO "\"",$query->remote_addr(),"\", "; } if ($value =~ /^pfReferer/) { print INFO "\"",$query->referer(),"\", "; } } #print "$key:$value"; } print INFO "\"complete\"\n"; close (INFO); print $query->redirect($redirect_to); exit(); ------------------------------------------------end of script

back to handbook chapter links