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
sub checkLogin {
my $loginName = shift;
# Do not clobber open FH file handles
local *FH;
my $file = $SETTINGS{userfile};
open FH, $file or die qq(Cannot open "$file": $!);
flock FH, LOCK_EX if $^O ne 'MSWin32';
while ( <FH> ) {
my( $user, $password ) = ( split /\t/, $_ )[1, 2];
if ( $user =~ m/^$loginName$/) {
if ( $password =~ m/^$password$/) {
return 'true';
}
}
}
close FH;
return '';
}
Example 3: Eliminating a flag variable.