Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Your Email:

Build a Perl/CGI Voting System

By Allan Peda
2005-07-05


CGI considerations: Simplicity vs. complexity

Perl seemed an obvious language to choose for this project -- it is supported on most typical platforms, and there are many convenient libraries available in the Perl library repository, CPAN.

As to underlying architectures, the Common Gateway Interface (CGI) was the first widely used approach to extend Web servers to provide interactive content. Developers often speak of the superiority of newer standards such as JSP, .NET, mod_perl, PHP, and ISAPI, and they are correct to point out CGI's deficiencies. But in the case of this project, a CGI script that counts votes for several hundred users hardly constitutes a large-scale application, since all ballot information can easily be held in the system RAM of the Web server. This allows the entire lookup table to be loaded into memory each time a user submits a request to read or write data.

Furthermore, the logical sequence of drafting a ballot, confirming a ballot, and tallying the results lends itself to splitting up the logical data into three different physical files. This would minimize attempts to open locked files.

There would also be no real penalty for a transaction failing occasionally due to a locked file. Whether a transaction failed due to network problems or a locked file, the result would be the same: The user would simply click a second (or third) time, then the vote would most likely be counted on one of those attempts. This behavior should be kept in mind, however, as a different application might not be as forgiving of an inability to process concurrent transactions.

For this project, CGI offers several advantages:

  • It needs no special Web server enhancements.
  • It requires no database engine (in this simple case).
  • It can be incrementally developed.
  • It can even be upgraded later through the use of accelerators such as mod_perl.

Keep in mind, however, that due to platform constraints, CGI applications (those that create new processes) run much slower on Win32 systems. Also, the Apache Web server is still considered a Linux™/UNIX®-hosted application, although it may run fine under Windows®. The Resources section offers information on another (non-IIS) Web server alternative for Win32 systems, as well as a classic explanation of the original CGI specification on the original National Center for Supercomputing Applications (NCSA) site.



Tutorial Pages:
» Using locked DBM files with CGI-driven forms saves client data without DBMS overkill
» CGI considerations: Simplicity vs. complexity
» Functional design considerations
» Details: Hash keys
» Details: E-mail gotchas
» Details: Not-so-secret ballots
» Details: File layout
» Details: Static vs. dynamic DNS
» Details: Is GET harmful?
» Other possible improvements
» Conclusion
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» Random subroutines in Perl
» Log Script Use
» Creating Perl Modules for Web Sites
» Bit Vector, Using Perl Vec
» Perl Range Operator
» Creating Perl Modules for Websites