in reply to Perlmonk's "best pratices" in the real world
When i started with perl, I was doing some CGI scripts using some sort of "readform" sub that tried to parse CGI params itself.
Eventually I found out that i could write "use CGI;" and it would do it all FOR me. That was pretty amazing to me. No more cutting and pasting of that half-asses sub.
Around the same time I learned about strict and warnings. What's this? Write two lines and it will find (some) problems with my script FOR me? Sweeet.
Generally, all of my programs looked something like this:
my $action = $cgi->param( 'action' ); if( $action eq 'show' ) { # ... } elsif( $action eq 'delete' ) { # ... } else { # ... }
After joining perlmonks, i found out about CGI::Application. It handles all of that messy if-elsif-else crap FOR me! At the same time, using HTML::Template allowed me to get rid of all of those pesky print q(...); and print << EOHEADER; statements and let my script focus on the data rather than the output.
Generally, my post can be summed up into: be lazy.
It really pays off. You get code re-use thus you have to write LESS code. Fewer, if any, cut & paste errors. Generally these modules are more robust and feature-rich than your code (because the module focusses on one single task).
Sure, no one is FORCING you to use these modules. You're welcome to write your own readform() sub as much as the next person. But... Why would you WANT to?
--
"To err is human, but to really foul things up you need a computer." --Paul Ehrlich
|
|---|