[Athens-pm] <a href="my_script.pl?argument1=string>Click this</a> can't fix it!

Philip Lees pjlees at ics.forth.gr
Fri Feb 28 04:09:33 CST 2003


Antonis Faragitakis wrote:

> > print_error_page and exit unless $cgi->param( 'user_name' ) and
$cgi->param( 'user_pass' );
> 
> Yes i know "There is more than one to do it!"
> but why mess with another sub routine, when i can
> add two more $variable in the code and not two new
> lines of code!?

One reason is that as your script grows and becomes more complex (as it
is likely to do) you can keep all your error messages together in one
sub that is called with an error number - and other arguments too, if
you like.

# missing user name or password

print_error_page(1) and exit unless $cgi->param( 'user_name' ) and
$cgi->param( 'user_pass' );

# password doesn't match

print_error_page( 2, $user_name ) and exit unless $users{ 'user_name' }
eq $user_pass;

# database error
print_error_page( 3, $DBI::errstr ) and exit unless $dbh->connect( ...
);

This makes it very easy to add new error messages. Also, you do all your
html output stuff only once, in the sub. You may even find that you can
copy your error message sub and use it in another script.

Philip
--
Philip Lees
Working Group on Cardiology
ICS-FORTH, Science and Technology Park of Crete
Vassilika Vouton, P.O. Box 1385, GR 711 10 Heraklion, Crete, GREECE

tel.: +30-2810-391680, fax: +30-2810-391601, e-mail: pjlees at ics.forth.gr

'The aim of high technology should be to simplify, not complicate' -
Hans Christian von Baeyer 




More information about the Athens-pm mailing list