Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-09-2008, 07:36 PM   #1
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Rep: Reputation: 30
Perl Noob + DBI : Can't call method without a package or object ref

The following code:

use DBI;
my %preparedStatements;
$preparedStatements{"latest_config_id"} = $db_handle->prepare("SELECT MAX(sequence) FROM configs WHERE id = ?")
    or die $db_handle->errstr;
sub get_latest_config_id($) {
    my ($id) = @_;
    my $ps = $preparedStatements{"latest_config_id"};
    my $result = $ps->execute(($id))
        or die $ps->errstr;
    my @row = $result->fetchrow_array();
    return $row[0];
Dies with "Can't call method "fetchrow_array" without a package or object reference at /usr/lib/perl5/ line 38."

Do I need to cast $result somehow?

Thanks in advance.
Old 09-09-2008, 08:13 PM   #2
Senior Member
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
first, ive used perl only for the past few months (and not very often) and i have never used DBI--only did basic perl stuff. however, the execute function i believe returns a true or false value. you then try to call the "fetchrow_array()" function on this variable, but i think you should be using $ps not $result.

Last edited by nadroj; 09-09-2008 at 08:16 PM.
Old 09-09-2008, 08:47 PM   #3
Registered: Jan 2004
Location: Australia
Distribution: Debian
Posts: 168

Original Poster
Rep: Reputation: 30
Ah, I understand now. You're quite right -

"For SELECT statements, execute simply ``starts'' the query within the database engine. Use one of the fetch methods to retrieve the data after calling execute. The execute method does not return the number of rows that will be returned by the query (because most databases can't tell in advance), it simply returns a true value."




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't call method "title" on undefined title in Perl script scuzzman Programming 12 12-11-2009 05:40 AM
Can't locate object method "splitpath" via package "PACK001" at /usr/lib/perl5/5.8.8/ sajigeorge Linux - Software 1 01-11-2009 07:33 AM
perl install error: Can't locate object method "new" via package "Module::Build::Vers powah Linux - Software 0 10-24-2006 02:57 PM
Perl undefined subroutine /can't locate object method cobien Programming 1 11-17-2003 11:47 AM
Can't locate object method "splitpath" via package "File::Spec" RobJohnston Linux - General 2 06-28-2003 10:59 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration