Cultured Perl: Embedding Perl in database tables
By Teodor Zlatanov2005-04-27
Compatibility with Other Languages and Alternative Approaches
If you thought "Hey, why just Perl?" when you read this article, you were not the only one. I considered writing this article for Perl and Java™ or other mixed-language environments, but Perl is singularly well suited for one-line templates. I believe that longer templates in multiple languages will make the system unmaintainable in short order, so I recommend sticking with one language if you can -- and let that language be succinct. Python may work instead of Perl (as it has fairly short database manipulation directives), but I haven't done a test implementation in Python.
The other idea everyone has when looking at this, sooner or later, is "Why not put the opcode-to-template translation table in the code?"
You can. I don't recommend it because you are effectively translating code twice, once from opcode to template, and then from template to actual code. You may as well just map the opcode "DELETE" to whatever function is appropriate for deletion in your environment and language, to take that example. The general idea of abstracting operations to simplify data management is valid, no matter how you implement it.
The key to the abstraction, expressed in templates or raw code, should be to simplify operations to the noun-verb or noun-verb-modifier forms. When you perform this abstraction, you will learn valuable lessons about the needs and wants of your software. You will understand the ways in which the software will get from any state to another state, and (very importantly) if you can define every operation, then you can track and undo it as well.
Tutorial Pages:
» Put Perl into your RDBMS Design to Reach Database Nirvana
» Class::DBI Capabilities
» Setting up Tables
» Embedded Deletion
» Embedded Modifications
» Compatibility with Other Languages and Alternative Approaches
» Conclusion
» Resources
First published by IBM DeveloperWorks
| Related Tutorials: » Random subroutines in Perl » Log Script Use » Creating Perl Modules for Web Sites » Bit Vector, Using Perl Vec » Build a Perl/CGI Voting System » Perl Range Operator |
