more useful options | |
PerlMonks |
Meditations on templatesby petethered (Pilgrim) |
on Apr 19, 2001 at 12:55 UTC ( [id://73774]=perlmeditation: print w/replies, xml ) | Need Help?? |
I use, and write, large numbers of CGI programs designed to
do various tasks. Everything from random display of data,
to complicated programs that do everything but flush the toilet
for you. One thing I come across alot in other peoples coding is the lack of templating. Programs that have the HTML hardcoded into it, making the programs inflexible and a pain to customize. Whenever I code, every piece of HTML outside of table internals ( and sometimes even them ) is templated. It makes code easier to read, and the software easier to work with. If you are one of those people who hardcode their HTML allow me to atleast give you a head start to my perceived path of "good" cgi programming. The template subroutine I use basically has these two lines of code in it: To insert the values of a var, %varname% is the command I use, and this is a working regexp that I haven't been able to break to insert the data. $line =~ s/\%([a-zA-Z0123456789\_\:]*)\%/${$1}/gi; And to insert the values of an hash, !array{key}! is the command and here is a regexp that MAY be breakable. I use this one for selects alot ( ie <option !selectcountry{USA}!> in the html, and in the CGI program $selectcountry{$FORM{country}} = "selected"; ) $line =~ s/\!([^ ]*)\{([^ ]*)\}\!/${$1}{$2}/gi; Please, for the love of Pete ( full pun intended ) use templates if you code CGI programs that make it into the wild. Pete insert into pete values('red hair','near green eyes','overinflated ego');
Back to
Meditations
|
|