http://qs1969.pair.com?node_id=11149875


in reply to Re^8: bug or curly bracket hell?
in thread bug or curly bracket hell?

There are 2 things you should be doing to make the code easier to understand and maintain. #1 is the logical use of blank lines to separate different concepts and proceses.

Illogical spacing:

open('conf', "$PATHconf") || die "can't open $PATHconf: $!\n"; my @conf = <conf>; close('conf'); my $i=0; foreach(@conf){ my $line = $conf[$i]; my $t= "".$i; my $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$ +VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; my $rowCount = 0; my $filename = "Output012023.xlsx"; my $workbook = Excel::Writer::XLSX->new( $filename ); open(FH, "<", "Debt.csv" ) or die;
Logical spacing:
open('conf', "$PATHconf") || die "can't open $PATHconf: $!\n"; my @conf = <conf>; close('conf'); my $i=0; foreach(@conf){ my $line = $conf[$i]; my $t = "".$i; my $dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$ +VARDB_port", "$VARDB_user", "$VARDB_pass") or die "Couldn't connect to database: " . DBI->errstr; my $rowCount = 0; my $filename = "Output012023.xlsx"; my $workbook = Excel::Writer::XLSX->new( $filename ); open(FH, "<", "Debt.csv" ) or die;
#2 is to add a comment every time you figure something out:
foreach(@conf){ my $line = $conf[$i]; # the reason for doing this weird thing my $t. = "".$i;
The comments will significantly reduce the cognitive load needed to comprehend the code by outsourcing all the reasons for this and that to brief human readable comments.