Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indentation causes problem

Status
Not open for further replies.

RPrinceton

Programmer
Jan 8, 2003
86
US
Hi,
The block of code between .a and .b works fine, the block of code between .c and .d fails with:
Bad switch statement (problem in the code block?) near PoolMaint.pl line 331. The only difference between the two is how I have indented the code in the script. The error isn't even close to the line number where this code is. It's almost as though Perl has some restriction or quirk with regard to indentation. Please advise. Thanks in advance. Regards, Randall Princeton

.a
sub getSeasonYear()
{
$sql = qq{SELECT * FROM $mvTblNM WHERE @mvWhere};
$sth = $dbh->prepare($sql);
$sth->execute($mvCntlKeyNbrQual,$mvCntlKeyTxtQual);
chkDBSelect();
$sth->bind_columns(undef,\$mvCntlKey,
\$mvCntlKeyNbrQual,
\$mvCntlKeyTxtQual,
\$mvCntlDesc,
\$mvCntlBegDT,
\$mvCntlEndDT,
\$mvCntlValu);
while ($sth->fetch())
{
print LOG "DB Record follows\n";
print LOG "CntlKey: $mvCntlKey\n";
print LOG "CntlNbr: $mvCntlKeyNbrQual\n";
print LOG "CntlTxt: $mvCntlKeyTxtQual\n";
print LOG "CntlDsc: $mvCntlDesc\n";
print LOG "CntlBDT: $mvCntlBegDT\n";
print LOG "CntlEDT: $mvCntlEndDT\n";
print LOG "CntlVal: $mvCntlValu\n";
}
}
.b

.c
sub getSeasonYear()
{
$sql = qq{SELECT * FROM $mvTblNM WHERE @mvWhere};
$sth = $dbh->prepare($sql);
$sth->execute($mvCntlKeyNbrQual, $mvCntlKeyTxtQual);
chkDBSelect();
$sth->bind_columns(undef,\$mvCntlKey,
\$mvCntlKeyNbrQual,
\$mvCntlKeyTxtQual,
\$mvCntlDesc,
\$mvCntlBegDT,
\$mvCntlEndDT,
\$mvCntlValu);
while ($sth->fetch())
{
print LOG "DB Record follows\n";
print LOG "CntlKey: $mvCntlKey\n";
print LOG "CntlNbr: $mvCntlKeyNbrQual\n";
print LOG "CntlTxt: $mvCntlKeyTxtQual\n";
print LOG "CntlDsc: $mvCntlDesc\n";
print LOG "CntlBDT: $mvCntlBegDT\n";
print LOG "CntlEDT: $mvCntlEndDT\n";
print LOG "CntlVal: $mvCntlValu\n";
}
}
.d
 
Chris,
Thanks for your response.
Here is the block of code that Perl says is failing when I indent. I have labeled line 331.

sub chkDBSelect
{
switch ($DBI::err) {
case (undef) {
}
else { print LOG "Err: $DBI::err, $DBI::errstr\n";
$mvHtmlmsg = "SELECT error on TABLE $mvTblNM, $DBI::err, $DBI::errstr";
retHTML($mvHtmlmsg);
close (LOG);
exit(0); <== line 331
}
}
}
Regards,
Randall Princeton


 
It seems to me like you'd want
Code:
sub chkDBSelect
{
    if ($DBI::err != undef)
    {
        print LOG &quot;Err: $DBI::err, $DBI::errstr\n&quot;;
        $mvHtmlmsg = &quot;SELECT error on TABLE $mvTblNM, $DBI::err, $DBI::errstr&quot;;
        retHTML($mvHtmlmsg);
        close (LOG);
        exit(0);
    }
}

//Daniel
 
Daniel,
Thank you for your response.
I realize there are many ways to code a solution. I believe
that &quot;case&quot; i.e., &quot;switch&quot; statements are easier to read, especially when you have nested &quot;ifs&quot;. In any event it still doesn't answer the question why indentation would cause a problem with a switch block many lines of code away from the indentation. I think Perl has some type of quirk with regard to line feed characters or certain chars in a line i.e., I think somehow Perl hasn't parsed the source properly.
Regards,
Randall Princeton
 
Randall,

To my knowledge switch as you're calling it isn't implemented into Perl. Have a look at page 104, Programming Perl by O'Reilly (Wall, Christiansen & Schwartz)

Regards
--Paul
 
Paul,
Thank you for your response. I have included a link
that points to the information regarding the switch construct in Perl. I have used the switch construct outlined in the documentation the attached link points to in other parts of my program and they all work perfectly and I find them to be much clearer that 'ifs'. For what ever reason the indentation makes my Perl script go crazy...if I remove the indentation the switch construct does not generate an error and the script runs perfectly. Here is the link pointing to the use of the switch construct in Perl. Regards,
Randall Princeton
 
You do realise that your 'link' refers to the
switch.pm perl module ?
Don't forget to call the module at the begining of your
script like this :

use Switch;


Crackn101

-----------------------------------------
There is a crack. A crack in everything.
That's how the light gets in.
-----------------------------------------
 
The line of code that it is refering to is the :

exit(0); <== line 331

stmt of the subroutine:

sub chkDBSelect

and in your indented block of code there is a call to
chkDBSelect();

This is why the error is saying that it is on line 331...
I don't know why it would couse an error, but this might help someone find it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top