Hey all,

In a web environment, how do you normally deal with messages whether it's to do with a failed or successful operation? Examples of such messages are:

a) Wrong input.
b) Thanks for signing up with us!
c) Go away, hacker.

I found this solution used by YaBB. The solution is to store an array of messages as follows:

my @msg; $msg[0] = 'Wrong input.'; # Doesn't say much but it's just an example $msg[1] = 'Thanks for signing up with us!'; $msg[2] = 'Go away, hacker.'; # Example of use... sub check_input { #blah blah... msg($[2]); } sub msg { my $msg = shift; start_html("Message"), print p("$msg"); end_html(); }
An advantage of storing messages in the above manner is that the same message can be shared by different parts of the code. Another is that when the message content is changed, the change is effected in all the places it's used.

One disadvantage is that you don't know what a message is unless you look it up in the array. For example, if $msg5 is used somewhere in the code, after a while you tend to forget what it is and have to look at the array code to figure it out. This problem becomes obvious when you have lots of such messages or when the array is stored in another file.

How would you normally do it?

Looking forward to hearing your replies :)


In reply to Ways to store messages... by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.