Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

On reflections

by kiat (Vicar)
on Dec 09, 2003 at 02:13 UTC ( #313348=perlmeditation: print w/replies, xml ) 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 :)

Replies are listed 'Best First'.
Re: On reflections
by pg (Canon) on Dec 09, 2003 at 04:31 UTC

    I have gone through a different path, but I share your feeling. This site is very helpful.

    My Perl knowledge comes from three sources, and only three sources:

    • Several chapters from Perl black book
    • Perl doc
    • By receiving and giving on this site.

    It was the summer of last year, I went to work for a different site of my previous company. I was asked to create a testing tool in Perl. I didn't know anything about Perl, other than vaguely knowing that it was a programming language. But I was quite experienced in IT in general, so I knew what I needed from Perl. I borrowed that Perl black book from someone, and started reading. I didn't have time for the entire book, as I was expected to deliver, so I only read the parts I really needed, like:

    • How to do socket programming in Perl,
    • How to use collection, like array and hash,
    • How to control flow, like while, if, for etc.
    • Part of my background was Java, so I naturally picked up Perl OO from the very beginning.

    The project was a success, and that's the only project I did in Perl. But I fell in love with Perl, and after that I started to create various tools for myself in Perl. If you ask me, why I loved Perl: Rapid development + Simple + Regexp.

    Other than that black book, I never read another Perl book, and as a matter of fact, I never owned any Perl book myself.

    I always believe that a programmer cannot dig out things from document and experiment, is not a good programmer. It was not easy to read Perl document, not because the content is hard, but because Perl document is not really well organized, at least for novice.

    Did I find this site through google? I cannot remember, but once I hit this site for the first time, I quickly figured out that this was a very useful Perl resource. I guess everyone had the experience that, sometime one even don't know which document to check for the answer of a particular problem, and sometime the answer is spreaded in several documents. For a novice that's too much, from time to time, when I needed some quick enlightment, I came to this forum to ask fellow monks.

    Giving is also a good way to learn. By writing up replies, and implemeting and testing demo codes, I learned a lot. Even when it is not something new to me, trying to answer it refreshes my memory. Sometime I saw questions I didn't have answers, but through digging into the document and conducting experiment myself, I helped myself at the same time when I helped others.

Re: On reflections
by petercooper (Acolyte) on Dec 10, 2003 at 08:03 UTC

    It sounds like you're making good progress. You're definitely thinking in a healthy way about it (there are a lot of people out there who swear they'll 'never' use certain methods - then do).

    I've done things in a similar way to you. My code when I started was horrific. It was like BASIC programming. Everything was done in tiny steps, tons of lines, no use of map or grep, if statements everywhere, no OO. I've been coding in Perl for 8 years now and it's only in the last few that I've mastered OO, the templating systems, and most of the idioms.

    I don't think you can rush all this. Of course, you could go a lot faster than I did (Perl wasn't my job for the first 4 years or so - just hacking together bits for my Web sites etc), but I don't think you should make giant leaps in multiple areas at the same time. Getting up to using databases is a great step, and now you can focus on the next one.

    Your strength with OO will come, in time, and you'll see new situations where it is highly useful. Of course, there are many cases where you won't want to use it, and quite rightly so :-) Just keep hacking, I say! Good luck!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://313348]
Approved by rob_au
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2017-01-20 08:15 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.