Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Returing Multiple Items and possibly using an object

by seattlejohn (Deacon)
on Nov 17, 2002 at 23:22 UTC ( [id://213616]=note: print w/replies, xml ) Need Help??


in reply to Returing Multiple Items and possibly using an object

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:

sub _format_error { return qq{<font face="Arial, Helvetica, sans-serif" size="2" color=" +red">$_[0]</font>}; } my $login_blocked = format_error('Login Blocked please wait 3 minutes +and try again'); # ...etc...
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';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://213616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found