http://qs321.pair.com?node_id=314259

kiat has asked for the wisdom of the Perl Monks concerning the following question:

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 :)