Perl: the Markov chain saw | |
PerlMonks |
Re: Returing Multiple Items and possibly using an objectby seattlejohn (Deacon) |
on Nov 17, 2002 at 23:22 UTC ( [id://213616]=note: print w/replies, xml ) | Need Help?? |
There are a couple of additional things you might do to improve the readability and maintainability of your code.
One Perlism that comes in hugely handy when you're generating HTML is the alternate string-quoting form. For example:my $html = qq{<font face="Arial, Helvetica, sans-serif" size="2" color="red">}; Note that you no longer have to escape the doublequotes, because qq{} lets you define alternate delimiters. I chose curly braces in this case because they're rare in HTML and minimize the amount of escaping you have to do, but other paired parenthetical characters work too, as do arbitrary non-parenthetical characters such as these:my $html = qq*<font face="Arial, Helvetica, sans-serif" size="2" color="red">*; (though I must admit I find that using asterisks as a delimiter is not so easy to read). qq{}, like double quotes, performs variable interpolation; q{}, like single quotes, does not. There's also qx{}, which is equivalent to backticks, and qr{} for constructing regexes. See the section "Quote and Quote-Like Operators" in perldoc perlop for more info. Secondly, you might want to factor out the HTML formatting, which seems to be the same for every message, into a subroutine or a constant. For example: That way you only have to change things in one place if you someday want to alter the HTML formatting. It also makes the list of messages clearer to someone reading your code because they don't have to figure out what's the actual text and what's part of the HTML formatting. Good luck! $perlmonks{seattlejohn} = 'John Clyman';
In Section
Meditations
|
|