How can I fix the error "Can't call method "id" on unblessed reference" for the following code? - sub language{
-
my $self = shift;
-
if (!$self->{LANGUAGE})
-
{
-
my @language = ();
-
my $statement = $db->prepare("select languageId, languageName
-
from language");
-
$statement->execute();
-
-
while(my @array = $statement->fetchrow_array()){
-
my ($id , $name) = @array;
-
my $object = Language->new();
-
$object->id($id);
-
$object->name($name);
-
push (@language, $object);
-
}
-
$self->{LANGUAGE} = \@language;
-
}
-
return $self->{LANGUAGE};
-
}
-
-
my @languagetest = language();
-
-
foreach my $current(@languagetest){
-
my $id = $current->id();
-
my $name = $current->name();
-
print "RETURN ID: [$id] Name: [$name] \n";
-
}
4 19339 miller 1,089
Recognized Expert Top Contributor
You do not show the code where the problem occurs. You create an object there: -
my $object = Language->new();
-
Therefore in the new method of the Language class, you should be returning a blessed data structure as is required in perl OOP (Object Oriented Prgramming). Where's your new method? are you blessing a hash or such? perldoc: perltoot - Tom's object-oriented tutorial for perl
- Miller
I try using foreach to print out the result - # my @languagetest = language();
-
#
-
# foreach my $current(@languagetest){
-
# my $id = $current->id();
-
# my $name = $current->name();
-
# print "RETURN ID: [$id] Name: [$name] \n";
-
# }
-
and it gives me an error of unblessed reference when i call the method id() again.. please help me to solve this problem. or does it have another to print out the result.
miller 1,089
Recognized Expert Top Contributor
Yes, because $current is not an object. You should know what type of data structure $current is, but if you don't use Data::Dumper -
use Data::Dumper;
-
-
my @languagetest = language();
-
-
foreach my $current (@languagetest) {
-
print Dumper($current);
-
my $id = $current->id();
-
my $name = $current->name();
-
print "RETURN ID: [$id] Name: [$name] \n";
-
}
Thank so very much for the above answer.
And I have another question as well. I did use the selectall_array _ref to execute this query. and when I try to print in the sub nextWords. it does work and prints out all the result that i have expected. - sub nextWords {
-
my ($id, $offset) = @_;
-
my @array = ();
-
my $statement = $db->selectall_arrayref("select word from words
-
left outer join language
-
on words.languageId = language.languageId
-
where words.languageId = $id
-
order by word asc
-
limit 10 offset $offset;");
-
-
my @main= ();
-
foreach my $i (@$statement)
-
{
-
push(@main, @{$i}[0]);
-
}
-
@array[$id] = [@main];
-
-
return @array;
-
}
-
-
my $lang_size = languages();
-
for my $id(1 .. $lang_size ){
-
-
print "=======ID = " . $id . "=======\n";
-
my $self->{CURRENTOFFSET} = 0;
-
NAME: while (1 > 0){
-
my @newwordsList = nextWords($id,$self->{CURRENTOFFSET});
-
-
$self->{CURRENTOFFSET}+= 10;
-
-
foreach my $k (@{@newwordsList[$id]}) {
-
print $k . "\n";
-
}
-
print "\n";
-
if (!@{@newwordsList[$id]}[0]) {
-
last NAME;
-
}
-
}
-
}
However, when i try to print out by create and other file.pl to compile it. it doesnt work, it give an error "DBD::SQLite::d b selectall_array ref failed: unrecognized token: "0x1db16c". - $object = DataLayer->new();
-
print $object->nextWords();
-
-
for my $id( 1 .. 3)
-
{
-
my $offset= 0;
-
NAME: while (1>0)
-
{
-
my @wordList = $object->nextWords($id, $offset);
-
$offset+=10;
-
foreach my $k (@{@wordList[$id]}) {
-
print $k . "\n";
-
}
-
if (!@{@wordList[$id]}[0]) {
-
last NAME;
-
}
-
}
-
}
-
thanks in advance..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Asyn lordasyn |
last post by:
Ok... I know there is got to be something simple that I forgot, but I for the life of me can't find it. Please, for the sake of the wall I keep slamming my head into, any insight would be helpful.
Every time I try and run my script I get: Can't call method "_not_worthless" on unblessed reference at /usr/lib/perl5/site_perl/5.8.0/Mail/Bulkmail.pm line 1700, <CONF> line 9
It's a pretty straight forward script (or so I'm thinking)
...
|
by: Jozef |
last post by:
Hello,
I have a friend in the UK and another in Denmark that I sent an Access XP
database to. I used the Package and Deployment wizard to create this file.
The only reference that I added was DAO 3.6. The users on the other side
of the ocean went through the set up and everything installed fine, but they
received an error indicitive of a reference error. The odd thing is, all
the references seem to be there. I CAN'T duplicate the...
|
by: Paul S. Natanson |
last post by:
What is a Null Reference error and how do I fix it?
My newly installed VB.Net2003 gives me a "Microsoft
Development Environment" error message box EVERY time I
try to run/start ANY project - even very simple ones.
The error says:
"An unhandled exception of
type 'System.NullReferenceException' occurred in
|
by: Paul S. Natanson |
last post by:
What is a Null Reference error and how do I fix it?
My newly installed VB.Net2003 gives me a "Microsoft
Development Environment" error message box EVERY time I
try to run/start ANY project - even very simple ones.
The error says:
"An unhandled exception of
type 'System.NullReferenceException' occurred in
|
by: Jeff |
last post by:
I'm getting an Object Reference error before I even run my app, and
I'm not sure where to look to find the cause. I'd appreciate your
help.
When I open my Windows Application project, the following Microsoft
Development Environment error message displays:
"Object reference not set to an instance of an object."
Then when I access the design view of one of my forms, the controls on
| |
by: vfunc |
last post by:
I get an undefined reference error for a definition that clearly looks
like it is in a .h file. So
what can be the cause of an undefined reference error, when this .h
file containing the definition has been included and the namespace has
been declared.
I blame engineers they are all ponsey zealots.
|
by: Dikbill |
last post by:
Hi there,
I've got a Windows project with references to an ocx file.
When I run the executable and the referenced ocx isn't
available I get a Windows error.
How can I trip a reference error so that I can display a
readable error message?
|
by: tonym415 |
last post by:
I think this is a reference error. All of a sudden my database doesn't
know what a "control" is. I have written forms and I get a "Module Not
Found" error. The line that is highlighted is a sub definition. (Sub
tbFormat(ctl As control))
I've tried fudging it and changing the statement to: Sub tbFormat(ctl
As object) then I get an error in another module on a line saying the
following: dim db as database.
I think there has to be some...
|
by: MattB |
last post by:
I'm relatively familiar with asp.net and vb.net and have been working in
the environment for several years. I've dealt with null reference errors
before and generally know how to code around them
But now I have some new code I deployed and I'm getting a null reference
error when looping through a datatable (for each r in dt.rows...).
I'm expecting to find an integer in this field, or possibly nothing, or
possibly a dash (-).
So I added...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |