|Do you know where your variables are?|
On reflectionsby kiat (Vicar)
|on Dec 09, 2003 at 02:13 UTC||Need Help??|
I had been using flat files for some time and thought nothing about mixing code and content in all my scripts. Thanks to the people of this community, I've recently switched to a proper database and have begun to use a templating system. It's beginning to get exciting again...
On flat files perl cgi and flat textfile
I had been happy using flat files for storing data in web-based applications. Never mind the long hours spent on coding to perform ADD, UPDATE and DELETE. And never mind the fact that there's a real possibility that the files can become corrupted especially when rat-race conditions arise. And a host of other problems.
I was reluctant to make the switch to a proper database for a number of reasons. First, the amount of data that needs to be stored is small. Second, I know nothing about databases, much less to use perl to interact with one. Finally, I was lazy to learn :)
Now that I've begun to explore a database system (MySQL), I'm beginning to discover how things which would have been a nightmare to do with flat files have become not just simple, but more importantly, enjoyable. I don't think I'll ever make an U-turn.
However, I must add that I've learnt perl (e.g. regex) through manipulating flat files :)
On HTML::Template pulling content from db - is it a good idea?
This must have been one of my latest prized discoveries. I'm now able to separate most of the code from the content. Not only that, I'm also encouraged to re-use a particular template as much as possible. For instance, I've a template that is used for forms with different number of fields formatted in a table.
On OO perl vs plain perl perl OO - to use or not to use
Although I've successfully experimented with simple OO code, I find myself still using plain perl i.e. using method calls ( method($var) vs $result = $obj->method($var) ). Maybe OO perl is a little too abstract for a mere mortal like me. However, while I used to put every sub in a single main script, I now place related subs in modules and have the scripts call these subs using 'use'. It's so much cleaner now.
Without the help of this community, I would never have ventured out of the well and would still be thinking in terms of line after line of data and inspecting my code to tweak an html element or two.
Many thanks :)