views:

504

answers:

4

What are the most common reasons that I would be getting this error from running a Perl script:

Memory fault(coredump)

I am running two SQL commands beforehand that only store ~1500 rows each with 6 fields. The SQL works fine out of the script, so I don't think I'm getting the error from that. And half of my code runs before it takes a bomb and gives me that error.

So what are the most common reasons for this error and what might my reason be?

EDIT - heres the code that works

my $i;
$i = 0;    
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
         if ($i == 1)
         {
          $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
          $rowfetch =~ s/(?=..$)/:/;
          printline($rowfetch);
          $i++;  
         }
         if ($i == 2)
         {
          $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
          $rowfetch =~ s/(?=..$)/:/;
          printline($rowfetch);
          $i++;  
         }
         if ($i == 10)
         {
          $rowfetch = $DBS->{Row}->GetCharValue("meetdays");
          $rowfetch =~ s/-//gi;
          printline($rowfetch);
          $i++;
         }
         if ($i == 12)
         {
          $rowfetch = $DBS->{Row}->GetCharValue("fullname");
          my ($lname, $fname) = split /,\s*/, $rowfetch;
          $rowfetch = $fname;
          printline($rowfetch);
          $rowfetch = $lname;
          printline($rowfetch);
          $i=$i+2;
         }
         else
         {
          $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
          printline($rowfetch);
          $i++;
         }
        }
        $i=0; 
        printf $fh "\n";
    }

Heres the code that doesnt work - All that was done was optimizing the sql fetch command

my $i;
$i = 0;      
while ($DBS->SQLFetch() == *PLibdata::RET_OK)
    {
        while ($i != $colnamelen)
        {
                $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]);
         if ($i == 1)
         {
          $rowfetch =~ s/(?=..$)/:/;
          printline($rowfetch);
          $i++;  
         }
         if ($i == 2)
         {
          $rowfetch =~ s/(?=..$)/:/;
          printline($rowfetch);
          $i++;  
         }
         if ($i == 10)
         {
          $rowfetch =~ s/-//gi;
          printline($rowfetch);
          $i++;
         }
         if ($i == 12)
         {
          my ($lname, $fname) = split /,\s*/, $rowfetch;
          $rowfetch = $fname;
          printline($rowfetch);
          $rowfetch = $lname;
          printline($rowfetch);
          $i=$i+2;
         }
         else
         {
          printline($rowfetch);
          $i++;
         }
        }
        $i=0; 
        printf $fh "\n";
    }

Oh and by the way, there is a functioning SQL statement before this while loop goes into action.. I just didnt want to waste space.

+4  A: 

You're tickling a bug in the Perl interpreter or one of its C modules. If your Perl binary doesn't have debugging symbols, compile a version that does and make a core dump. Load the core dump into gdb and do a back trace. Find the bug, see if it's in the latest version, and if it isn't, then submit a patch that fixes it.

Glomek
what if i threw in the fact that i have another script that runs fine, and the one that gives me the error is a spawn test script of the one that runs fine.. and everything is the same except i select less items in the 2nd sql statement?
CheeseConQueso
How are you doubling it? Fork, or threads?
J.J.
I don't even know what that means. I just made a copy of the actual file and saved it as facultytest.pl instead of faculty.pl
CheeseConQueso
+2  A: 

I have seen similar events when the DBD driver is compiled against a different version of the shared library than is currently on the system. (Such as would be the case of having MySQL4, and then upgrading to MySQL5 without recompiling the DBD)

Arcane
+4  A: 

Can you reduce the problematic script to something short that shows the same error? Where in the script does it dump core?

My first suspect would be one of the modules you are using has an XS component that isn't playing nicely. Find out where the script blows up, then start investigating the parts around there. Keep cutting out parts until you can come up with the smallest script which reproduces the problem.

brian d foy
Thanks for the advice.. I have tried that and it's very demonic in how it delivers me my useless coredump. It dumps right before a while statement that acts as a rowfetch for the sql command. Right above that while stmt is a printf $fh "\n";.. Nothing works under that.. n.e. another printf stmt
CheeseConQueso
brian... any input?
CheeseConQueso
+1  A: 

Before the code change, you called GetCharValue after checking if $i was as value you wanted. After the change, you call it even if it's not 1,2,10,12. Is it possible that the values for $i other than those 4 is causing the issue?

Tracy Hurley
$i is initialized and set to 0 before the first while loop starts.. i should have included that.. and yes.. $i increments by 1 each time the nested while loop runs and gets set to 0 again in the outer while loop so that the nested can run 'i' amount of times again for each query result row
CheeseConQueso
also ... colname is an array containing field names and $colname[$i] when $i is between 0 and 14 is never null
CheeseConQueso
actually, $i increments by 1 if it's not 1,2,10,12, 2 if it's 1, 10 or 12, and 3 if it's 2.How is $colnamelen set?
Tracy Hurley
Try this as the second while loop: while ($i < $colnamelen) {
Tracy Hurley
$colnamelen = @colname; - it increments by 1 every time except in the case of element 12 where it splits one result into 2 fields and then increments i by 2
CheeseConQueso
it cant be that either... for example.. if i simply change $rowfetch = $DBS->{Row}->GetCharValue("fullname"); TO $rowfetch = $DBS->{Row}->GetCharValue($colname[$i]); (in the first code sample) i get the same error
CheeseConQueso
the top code works fine and outputs my csv just the way i want it... but it just really is weird how i cant optimize it without getting that error... im not really changing the logic, just removing the redundancy
CheeseConQueso
have you tried printing out $i and $colname[$i] to see if they have the values you think they have? For instance, you say that you increment by 1 each time through, but you increment in each of the first 3 if statements and then in the else statement (for all values of $i that are not 12).
Tracy Hurley
Given your comment regarding changing from fullname to $colname[$i], I'm wondering if $colname[12] doesn't have the value fullname.
Tracy Hurley
no, $i only increments by 1 each time except for when $i=12. if that were not the case, I would never have seen a csv file that worked yet. and yeah, I do incrememnt $i in each of the first 3 if statements, but only if they are true
CheeseConQueso
ok, nevermind. But could you check to see what value is in $colname[12] when you get to that if statement since it seems like you can't change it out in the original either?
Tracy Hurley
I know for a fact what $colname[12] is because I initialize it... push(@colname,"camploc","stime","etime","sdate","edate","secno","courseno","courname","bldg","room","meetdays","actenrol","instfnam","instlnam","depart","fclemail");
CheeseConQueso
i figured it out... its kind of related to what you were thinking about how $i doesn't increment by 1 every time... but if not for you, i wouldn't have thought to try what just fixed it !! thanks
CheeseConQueso
Glad you fixed it!
Tracy Hurley