473,804 Members | 3,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is an unblessed reference error?

47 New Member
How can I fix the error "Can't call method "id" on unblessed reference" for the following code?

Expand|Select|Wrap|Line Numbers
  1. sub language{
  2.     my $self = shift;
  3.     if (!$self->{LANGUAGE})
  4.     {
  5.         my @language = ();
  6.         my $statement = $db->prepare("select  languageId, languageName
  7.                                         from language");
  8.         $statement->execute();
  9.  
  10.         while(my @array = $statement->fetchrow_array()){
  11.             my ($id , $name) = @array;
  12.             my $object = Language->new();
  13.             $object->id($id);
  14.             $object->name($name);
  15.             push (@language, $object);    
  16.         }            
  17.         $self->{LANGUAGE} = \@language;
  18.     }
  19.     return $self->{LANGUAGE};
  20. }
  21.  
  22. my @languagetest = language();
  23.  
  24.             foreach my $current(@languagetest){
  25.             my $id = $current->id();
  26.             my $name = $current->name();
  27.             print "RETURN ID: [$id]  Name: [$name] \n";
  28.             }
Feb 25 '11 #1
4 19339
miller
1,089 Recognized Expert Top Contributor
You do not show the code where the problem occurs. You create an object there:

Expand|Select|Wrap|Line Numbers
  1. my $object = Language->new();
  2.  
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
Feb 25 '11 #2
Wiinie
47 New Member
I try using foreach to print out the result
Expand|Select|Wrap|Line Numbers
  1. # my @languagetest = language();
  2. #  
  3. #             foreach my $current(@languagetest){
  4. #             my $id = $current->id();
  5. #             my $name = $current->name();
  6. #             print "RETURN ID: [$id]  Name: [$name] \n";
  7. #             }
  8.  
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.
Feb 25 '11 #3
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

Expand|Select|Wrap|Line Numbers
  1. use Data::Dumper;
  2.  
  3. my @languagetest = language();
  4.  
  5. foreach my $current (@languagetest) {
  6.     print Dumper($current);
  7.     my $id = $current->id();
  8.     my $name = $current->name();
  9.     print "RETURN ID: [$id] Name: [$name] \n";
  10. }
Feb 25 '11 #4
Wiinie
47 New Member
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.


Expand|Select|Wrap|Line Numbers
  1. sub nextWords {
  2.     my ($id, $offset) = @_;
  3.     my @array = ();
  4.     my $statement = $db->selectall_arrayref("select word from words 
  5.             left outer join language
  6.             on words.languageId = language.languageId
  7.             where words.languageId = $id
  8.             order by word asc
  9.             limit 10 offset $offset;");
  10.  
  11.     my @main= ();
  12.     foreach my $i (@$statement)
  13.     {
  14.         push(@main, @{$i}[0]);
  15.     }
  16.     @array[$id] = [@main];
  17.  
  18.     return  @array; 
  19. }    
  20.  
  21. my $lang_size = languages();
  22. for my $id(1 .. $lang_size ){
  23.  
  24.     print "=======ID = " . $id . "=======\n";
  25.     my $self->{CURRENTOFFSET}  = 0;
  26.     NAME: while (1 > 0){
  27.         my @newwordsList = nextWords($id,$self->{CURRENTOFFSET});
  28.  
  29.         $self->{CURRENTOFFSET}+= 10;
  30.  
  31.         foreach my $k (@{@newwordsList[$id]}) {
  32.             print $k . "\n";
  33.         }
  34.         print "\n";
  35.         if (!@{@newwordsList[$id]}[0]) {
  36.             last NAME;
  37.         }
  38.     }
  39. }
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".

Expand|Select|Wrap|Line Numbers
  1. $object = DataLayer->new();
  2. print $object->nextWords();
  3.  
  4. for my $id( 1 .. 3)
  5.     {
  6.         my $offset= 0;
  7.         NAME: while (1>0)
  8.         {
  9.             my @wordList = $object->nextWords($id, $offset);
  10.             $offset+=10;
  11.             foreach my $k (@{@wordList[$id]}) {
  12.             print $k . "\n";
  13.             }
  14.             if (!@{@wordList[$id]}[0]) {
  15.             last NAME;
  16.             }
  17.         }    
  18.     }
  19.  
thanks in advance..
Feb 25 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7268
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) ...
2
1793
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...
16
2312
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
1
1354
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
2
2219
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
40
3229
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.
2
1249
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?
9
6215
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...
5
1511
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...
0
9706
marktang
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...
0
10580
Oralloy
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...
0
10335
jinu1996
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...
1
10323
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,...
0
10082
tracyyun
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...
0
9157
agi2029
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...
0
5525
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...
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.