|
Helping ordinary people create extraordinary websites! |
Build a Perl/CGI Voting SystemBy Allan Peda2005-07-05
Details: Hash keys The use of hashed keys to create associative arrays in Perl allows on-the-fly development of complex data structures. When you combine this feature with the ability to store these (arbitrarily complex) structures in a binary DBM file, you can develop what amounts to a tiny database system. The missing component that allows all of this to work is provided by the MLDBM and MLDBM::Sync modules. The Essentially, the logic flow is as simple as that shown in Listing 1. Listing 1. Pseudo-code logic flow
Once I had decided what the underlying conditional flow would be, the only remaining task was to construct objects that would fit into this sequence of actions. As I noted previously, the necessary hash data structures were retrieved and updated using In other words, the list of ballots was used to construct a On another tangent, while I understand that it is generally considered poor practice to have constructors that rely on external resources such as files (since they could fail and wind up in an unpredictable state), the code in this case was much easier to understand by doing just that. Since Perl doesn't rely on pointers, I can see no reason not to take advantage of this simplification. 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
|
|