Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^9: bug or curly bracket hell?

by Anonymous Monk
on Jan 25, 2023 at 16:58 UTC ( [id://11149875]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11149875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-07-21 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.