Coding for Readability
By Charles K. Clarkson, March 01, 2005
Coding style is key to making sure your programs are maintainable. What's more, it can reduce the errors in your code.
March, 2005: Coding for Readability
# function that will check to ensure the username are
# password match and are ok
sub checkLogin {
my ($loginname) = @_;
open USERFILE, " $SETTINGS{'userfile'}"
|| die "Failed to open file: $!";
if ($^O ne "MSWin32") { flock(USERFILE, LOCK_EX); }
while (<USERFILE>) {
my @fields = split(/\t/,$_); # split $line, using : as delimiter
if (@fields[1]=~m/^$loginname$/) {
if (@fields[2]=~m/^$password$/) {
$matchokay='true'; # login name matches password
}
}
}
close(USERFILE);
if ($matchokay) { return $matchokay; }
else { return ''; }
}
Example 1: Hard-to-read code.