Perl: the Markov chain saw | |
PerlMonks |
Re: Perl Programming guidlines/rulesby hardburn (Abbot) |
on Nov 21, 2002 at 16:00 UTC ( [id://214801]=note: print w/replies, xml ) | Need Help?? |
5. OO always to be used where possible For CGI scripts, I don't see the point. Most CGI scripts are going to have around 100-200 lines of real code (not including the stuff that is just outputing HTML). While using OO-based modules is a good idea, it seems like overkill for the script itself. 17. Assign CGI parameters to hashes OK, let's give the mandatory "Global Variables are Bad" (tm). Fine. In CGI scripts, I prefer to put options passed to the script in global vars. Every function can get that information anyway, we just make it easier this way. Each of my scripts has a set_params() function that is the only function allowed to change those global vars. Example:
(I rarely use the fancy features of CGI.pm, so I usually don't bother with the OO interface, though I probably should). The problem with putting them into a hash is that you take away many of the benifits you get from "use strict 'vars'". 7. No hardcoding of values especially file paths, script names etc How do you get the config file without hardcoding the path to it? Update: For config files, I suggest being very careful with absolute paths. At my job, we recently moved to a new server, and we had a lot of problems with scripts that were using absolute paths that were no longer available on the new server. Additionally, our test server had some paths to the server's directory that didn't exist on the production server, which broke even more stuff.
In Section
Meditations
|
|