Solved

Perl Can't call method "finish" without a package or object reference at --> address

Posted on 2004-08-26
21
6,584 Views
Last Modified: 2008-01-09
Hello All;

  As you can tell by the title, I am have a really bad couple of days trying to figure this one out.

Just to get the balling rolling here.
This error accures when the script is called.
Here is the code for the "Line" that this error is referring to:

}
#==========================================================
sub DB_Disconnect{

   $sth->finish if($sth);  # line that is receiving the error
   $dbh->disconnect if($dbh);

}
#==========================================================


Can someone please give me an idea of what is going on here?
I have spent the last few days searching the internet, and not finding nothing on this error.

Thank You
carrzkiss
0
Comment
Question by:Wayne Barron
  • 10
  • 6
  • 2
  • +1
21 Comments
 
LVL 3

Expert Comment

by:terageek
ID: 11908899
You will get this error if $sth is not false (undef, '' or 0), but not a reference to an object either.  You can use the debugger to break on this line and check the value of $sth.

You may be able to hack around the error with the following...

$sth->finish if(ref $sth);

But the above is really a hack to get around the real issue that $sth is being incorrecly set to something other than a package/object reference.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11909333
Are you using global variables?  Where is the $sth object created?
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11909408
Should have listed this to begin with
This script is running on:

WinNT4 Server Running  IIS4

Hello terageek;
I tried the HACK and it did not work, it just gave me a "Blank Page"

I am not the one that programmed this, and I do not know anything about perl, except what I am learning as I go with this script.

Tintin;
   I have no Idea on rather or not it is using "Global Variables" or not.

What it is, this program is a Search Engine, When you click on the link that apears in the search list, it calls for:    go.cgi
In this file, the code that is activated is:

#==========================================================
sub Jump{
my($ID) = @_;
my($Query, $URL, $Temp, $sth);

      $Query = qq!SELECT URL FROM Links WHERE ID=$ID LIMIT 1!;
      $sth = $dbh->prepare($Query) || &DB_Exit($Query."<BR>Line ". __LINE__ . ", File ". __FILE__);
      $sth ->execute || &DB_Exit($Query."<BR>Line ". __LINE__ . ", File ". __FILE__);
      #while ($Temp = $sth->fetchrow_hashref){%Link = %{$Temp};}
      while (($Temp) = $sth->fetchrow_array){$URL = $Temp;}
      $sth->finish;
       print "Location: $URL\n\n";
}
#==========================================================

Which this code above make refrences to the file    sqlserver.cgi
Which this line is called

$sth->finish if($sth);  


I do not know what none of it means, so I am at a loss badly.

Thank you for any further assistance/help

carrzkiss
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11909508
the $sth object is local to the Jump subroutine and is therefore no visible in the DB_Disconnect subroutine.  You need to pass a reference to the object to the DB_Disconnect subroutine.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11909572
Hello Tintin;

 As mentioned above, I do not know nothing about Perl, except what I am currectly learning.
Could you please let me know how this is done? Please.

carrzkiss
0
 
LVL 8

Expert Comment

by:davorg
ID: 11910569
Where is the DB_Disconnect subroutine called from? Is there a $sth variable in scope at that time?

Does the program run with "use strict" and "use warnings". And if not, why not?

If you don't know much about Perl then why are you trying to fix a Perl program? Surely you should be going back to the original author or hiring someone who knows more Perl than you?

Dave...
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11917196
Here is where "DB_Disconnect" is called from, and it is at the end of the
sqlserver.pm ( sqlserver.cgi ) my mistake on the extension above.

#==========================================================
sub DB_Exit{
my($Query, $Title, $Level)=@_;
my ($Out, $Message);

      if ($Title eq "") {$Title="SQL Error";}
      if ($Level !~ /^\d+$/) {$Level=1;}
      if (!$Query) {
                  $Query = "";
      }
      else{
                  $Query="<b>Query</b>: <br>$Query.<br>";
      }
      $Message="SQL Error: $DBI::errstr<br>$Query";
      $Out=&DB_Error_Msg($Title, $Message, $Level);
      print "Content-type: text/html\n\n";
      print "$Out";
      
      &DB_Disconnect();
      exit (0);
}
#==========================================================

[davorg];

I am trying to learn, rather or not I will be able to figure this issue out on my own or with help from experts in the Paerl Field, is yet to be seen.
Please do not knock me for trying to "want to" figure this out.
Yes I have contacted the programmer of this script, and yes they are trying to assist me as well, but I want to try to help them in finding out what is causing the problem.
So please if you have any information that can assist me in this issue please let me know.
And if there is something else that I might need to supply, "explain" to me what it is?
But Please do not treat me like someone that should not be trying to figure out a problem that I should not be missing with. How am I suppose to learn?
I learned how to program in ASP by trial and error, and fixing BUGS in peoples scripts, That is always the fun part, getting your hands dirty in someone else code, and asking for advice from people who know more then you.
That is what EE is here for, and that is why I have been a member for almost 2yrs now.
To Help and to get Help.

Thank You
carrzkiss
0
 
LVL 3

Expert Comment

by:terageek
ID: 11917907
One thing that concerns me is that the error message is "Can't call method "finish" without a package or object reference at...". If $sth is undefined, Perl wouldn't try to call finish because the if would fail, and if it somehow didn't fail, you would get the error message "Can't call method "finish" on undefined value at..." instead.

Can you put a print statement in before $sth->finish() if ($sth);?
print "STH is:\"$sth\"\n";

And let us know what the output is?

You should be able to get rid of the error if you change the line to:
$sth->finish() if (ref $sth);

Adding the ref will cause perl to only try to call the subroutine if $sth is a reference to something.  It would probably be better to investigate what $sth is and how it got that way.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11918152
This is what I got

STH is:"DBI::st=HASH(0x16a4e60)"
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:terageek
ID: 11918315
What that is telling you is that $sth is an object reference of type DBI::st.  This contradicts the error message that you have which said that finish could not be called without a package or object reference.  Did you get the same error again after that was printed out?

Here is one more hack to try...
&DBI::st::finish($sth) if ($sth);

Normally, $sth->finish() will cause perl to try to figure out what type of object $sth is, then look for the method finish in that class to call, passing $sth as the first argument.  The line above will tell perl to skip trying to try to call the method finish in DMI::st, regardless of what type of object $sth is.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11918410
added in the last hack there, and got this Software Error:

Invalid DBI handle '0E0' at -:/---/----/---/cgi-bin/dir/sqldriver.pm line 1199.

And to answer your question about " Did you get the same error again after that was printed out? "   No, it was a blank page with only what was printed


0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 11983050
Just wanted to check in on this one? To see if anyone has any idea's?

I have built a new server, with a faster processor, and installed it from the groud up.
And then installed the script again, and still the same dag-on Software Error.

Any idea's on this would be really great. it is really getting to me,
And the developer does not seem to have a clue what it could be.
So I have suggested to him, to ask one of his customers that is running
The same setup as I am, and see what he says.

So until then.

carrzkiss
0
 
LVL 3

Expert Comment

by:terageek
ID: 12019388
FYI...

O'Reilly has a book on Perl DBI programming, and online is chapter 4, which you may at least find somewhat useful.

http://www.oreilly.com/catalog/perldbi/chapter/ch04.html

The best that I can figure, $sth is an object for a database query, and before disconnecting from the database, the code wants to make sure that any existing query finishes before disocnnecting.  Apparently, checking the existance of $sth is not enough to tell if it is a valid query.  There is probably some accessor fuction or flag within the object that you can check.  I am not familiar enough with DBI to know exactly what functions or flags you can check.

If you would like, you can try printing out the keys/values of $sth to try to find a flag that you can test.  It may be worth a shot anyway.
The following code will print out what data $sth contains that you might be able to test for.

foreach (sort keys %$sth) {
   print "$_\t$sth->{$_}\n";
}
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12022885
Hello [Terageek];
 
  I added that code in. And I receive the following error message now.
Pointing to the exact same place as the other one.

Can't call method "finish" on unblessed reference

Just a little different then the original one.
I am doing some searching to see if I can get some information on it now.
Also, I am checking in on DBI Modules. To see if maybe there is one that I am missing.

p.s.
  I am using " ActiveState Perl " On my WinNT4 IIS Server.
Is this the best one to use for Windows based applications?
Or is perl.com's script better?

Thank You
Wayne
0
 
LVL 3

Expert Comment

by:terageek
ID: 12031451
The fact that nothing was printed tells me that $sth is defined, blessed, but empty.  You can test to see if $sth is empty before trying to call $sth->finish() by doing the following...

$sth->finish() if ($sth && (keys %$sth));

The above isn't really ideal since you would be spying into $sth to see if it is empty, when there really should be some accessor function to use. I am really not familiar enough with DBI programming to know what functions are available.  Anyway, it should get rid of the error.

As for your p.s., sorry, but I don't do Windows.  If you submit it as a 20pt question I am sure that you will either get a quick answer, or a very long discussion.
0
 
LVL 30

Accepted Solution

by:
Wayne Barron earned 0 total points
ID: 12041228
I figured this one out finally.
Perl was messed up, and when I installed the Script, it did not install properly.
So blowing out perl, and then reinstall Perl, adding in all the Modules.
Then reinstalling the Script, everything went to working.

Anyway, Since [Terageek] attempted to assist me on this matter/issue.
I have awarded him the points.

Thank You for your assistance, I learned some good information from you.

carrzkiss
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12041463
[jmcg]

  I will leave it up to terageek.
If he thinks that it deserves another grade, then please by all means give it to him,
For the assistance that he has given me, though it did not solve the issue.
It was a great learning experiance. So if you can, keep it Visible, and give
Terageek, another grade. Which ever "He" prefers.

Thank You
carrzkiss
0
 
LVL 3

Expert Comment

by:terageek
ID: 12057818
Although I tried to help, the path that I went down wasn't the right one.
I really don't care about the points.  Since carrzkiss found the solution, I'd say give the points back.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 12057945
[jmcg]

 Go on ahead and "PAQ" it/Refund points.

Terageek, thanks for the information that you shared with me. I go an eye up on
How to do certain things in Perl/CGI with what you supplied.

Take Care
carrzkiss
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now