I was able to shorten my code by 100 lines taking in the advice. I can use it with perl -c, but I've run into another issue.. I'm getting use of uniniatlized value for each DB varible in the SQL part of the code to connect to the db, for example use of uniniatlized value $VARDB_database in concatenation or string at line 29. Each line the program reads it says, argument "SRC 125,Emma,,boston,,in,48011,8123456787" isnt numeric in array element at line 118. input same line is: SRC 125 "Emma Boston IN 48011 8127429212 emmaboston2011@icloud.com." its a 20000 line excel doc. Tried googling the error codes and ask my coworker but no such luck, my coworker and the one before him have never bothered with strict so all of our perl scripts don't use it. This is what I have now.
print " use strict; use warnings; use Excel::Writer::XLSX; use DBI; use Time::Piece; use Math::Round; #path to astguiclient configuration file: my $PATHconf = '/etc/astguiclient.conf'; my ( $PATHlogs, $VARserver_ip, $VARDB_server, $VARDB_database, $VARDB_user, $VARDB_pass, $VARDB_custom_user, $VARDB_custom_pass, $VARDB_port); 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; my $worksheet = $workbook->add_worksheet('List'); my $worksheet2 = $workbook->add_worksheet('List2'); my $format = $workbook->add_format(); my $format1 = $workbook->add_format(); #my $format2 = $workbook->add_format(); $format->set_center_across(); $format1->set_color( 'red' ); #$format2->set_bold(); #print join("\n", map { s|/|::|g; s|\.pm$||; $_ } keys %INC); #proper format must be used for the file or it will give an error $worksheet->set_column( 8, 8, 20 ); $worksheet->set_column( 10, 10, 15 ); $worksheet->set_column( 4, 4, 18 ); #$worksheet->set_column( 5, 5, 15 ); #$worksheet->set_column( 12, 12, 65 ); $worksheet->write(0, 0, "source_id" ); $worksheet->write(0, 1, "first_name" ); $worksheet->write(0, 2, "middle" ); $worksheet->write(0, 3, "last_name" ); $worksheet->write(0, 4, "address1" ); $worksheet->write(0, 5, "city"); $worksheet->write(0, 6, "state"); $worksheet->write(0, 7, "postal_code"); $worksheet->write(0, 8, "phone_number"); $worksheet->write(0, 9, "address3"); $worksheet->write(0, 10,"province"); $worksheet->write(0, 11, "email"); my $rowCount1 = my $rowCount2 = 0; #$worksheet2->set_column( 8, 8, 20 ); #$worksheet2->set_column( 10, 10, 15 ); #$worksheet2->set_column( 4, 4, 20 ); #$worksheet2->set_column( 5, 5, 15 ); #$worksheet2->set_column( 12, 12, 62 ); $worksheet2->write(0, 0, "source_id" ); $worksheet2->write(0, 1, "first_name" ); $worksheet2->write(0, 2, "middle" ); $worksheet2->write(0, 3, "last_name" ); $worksheet2->write(0, 4, "address1" ); $worksheet2->write(0, 5, "city"); $worksheet2->write(0, 6, "state"); $worksheet2->write(0, 7, "postal_code"); $worksheet2->write(0, 8, "phone_number"); $worksheet2->write(0, 9, "address3"); $worksheet2->write(0, 10,"province"); $worksheet2->write(0, 11, "email"); my $test=0; my $oZ=0; #RowCount1 writes for the whole page then 100 lines later it goes +to rowcoutn2 may need changed while (<FH>){ chomp; my @t= split(',',$_); if (length($t[8]) == 10) { # && (length($t[7])==4 || length($ +t[7])==5)) { if (!defined($t[7]) || $t[7] eq ''){ my $stmt ="SELECT postal_code, state FROM asterisk.vic +idial_postal_codes WHERE state='".$t[6]."' limit 1;"; my $sth = $dbhA->prepare($stmt) or die "preparing: ",$ +dbhA->errstr; $sth->execute or die "executing: $stmt ", $dbhA->errst +r; my $sthrows= $sth->rows; my $Count=0; #$z=""; while($sthrows>$Count) { my @ary = $sth->fetchrow_array; $worksheet->write($rowCount1+1, $_, $t[$_]); $worksheet->write($rowCount1+1, $_, $ary[$_]); $Count++; } } else { if (!defined($t[6]) || $t[6] eq '' || length($t[6])>2 +|| length($t[6])<2){ my $stmt = "SELECT state, postal_code FROM asteris +k.vicidial_postal_codes WHERE postal_code='".$t[7]."' Limit 1;"; my $sth = $dbhA->prepare($stmt) or die "preparing: + ",$dbhA->errstr; $sth->execute or die "executing: $stmt ", $dbhA->e +rrstr; my $sthrows=$sth->rows; my $Count=0; while($sthrows>$Count){ my @ary = $sth->fetchrow_array; $worksheet2->write($rowCount2+1, $_, $t[$_]); $worksheet2->write($rowCount2+1, $_, $ary[$_]) +; $Count++; } } else { $worksheet->write($rowCount1+1, $_, $t[$_]); } $rowCount1++; } } else { my $z=""; if (!defined($t[7]) || $t[7] eq '' || length($t[7])>5 || l +ength($t[7])<=3){ my $stmt="SELECT postal_code, state FROM asterisk.vici +dial_postal_codes WHERE state='".$t[6]."' and postal_code not in ('00 +501','00544') limit 1;"; my $sth = $dbhA->prepare($stmt) or die "preparing: ",$ +dbhA->errstr; $sth->execute or die "executing:$stmt ", $dbhA->errstr +; my $sthrows= $sth->rows; my $Count=0; $oZ=$t[7]; while($sthrows>$Count){ my @ary = $sth->fetchrow_array; $z=$ary[0]; $worksheet2->write($rowCount2+1, $_, $t[$_]); $worksheet2->write($rowCount2+1, $_, $ary[$_]); $Count++; } } else { if (!defined($t[6]) || $t[6] eq '' || length($t[6])>2 +|| length($t[6])<2){ my $stmt="SELECT state, postal_code FROM asterisk. +vicidial_postal_codes WHERE postal_code='".$t[7]."' Limit 1;"; my $sth = $dbhA->prepare($stmt) or die "preparing: + ",$dbhA->errstr; $sth->execute or die "executing: $stmt ", $dbhA->e +rrstr; my $sthrows=$sth->rows; my $Count=0; while($sthrows>$Count){ my @ary = $sth->fetchrow_array; $worksheet2->write($rowCount2+1, $_, $t[$_]); $worksheet2->write($rowCount2+1, $_, $ary[$_]) +; $Count++; } } else { $worksheet2->write($rowCount2+1, $_, $t[$_]) } } if (length($t[8]) < 10 || length($t[8]) > 10){ $worksheet2->write($rowCount2+1, 12, 'phone is incorre +ct.', $format1); } if (defined($z) || $z ne ''){ $worksheet2->write($rowCount2+1, 12, $oZ.' Zip code ha +s been updated '.$z.'.', $format1); } elsif (length($t[8]) < 10 || length($t[8]) > 10) { $worksheet2->write($rowCount2+1, 12, ' Zip code update +d, but has bad phone. ', $format1); } $rowCount2++; } } $rowCount++; } my $workbook->close(); #print $rowCount1.'-'.$rowCount2.'-'.$rowCount; close(FH);\n";

In reply to Re^4: bug or curly bracket hell? by MoodyDreams999
in thread bug or curly bracket hell? by MoodyDreams999

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.