if ( $user =~ m/^$loginName$/) {
      if ( $password =~ m/^$password$/) {
        return 1;
      }
    }


Becomes this:

    if (    $user     =~ m/^$loginName$/
        &&  $password =~ m/^$password$/ ) {
      return 1;
    }


Becomes this:

    return 1 if     $user     =~ m/^$loginName$/
                &&  $password =~ m/^$password$/;


Then goes back in as this:

  while ( <FH> ) {
    my( $user, $password ) = ( split /\t/, $_ )[1, 2];
    return 1 if     $user     =~ m/^$loginName$/
                &&  $password =~ m/^$password$/;
  }

Figure 1: Transforming if statements for readability.

Back to Article