473,473 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Printing array

47 New Member
I am new in Perl. and I am still very confused about printing the array..
Expand|Select|Wrap|Line Numbers
  1. my $object = Language->new();
  2.         #my $language = Language->id();
  3.                 my $language_id = $db->selectall_arrayref("select languageId, languageName
  4.                                                                                 from language");
  5.  
  6.  
  7.  
  8.                 foreach my $i (@$language_id){
  9.                 my ($id, $name ) = @$language_id;
  10.                 $object->id($id);
  11.                 $object->name($name);
  12.                 push (@language, $object);
  13.  
  14.                 @return=[@language] ;
  15.  
  16.                         foreach my $current(@return){
  17.                         my $id = $current->id();
  18.                         my $name = $current->name();
  19.                         print "ID: [$id]  Name: [$name] \n";
  20.                         }
  21.                 }
  22.  
  23. @return=[@language] ; <= this is a problem____
  24.  
because at the 1st time that I do not have this line of code @return=[@language] ;
it will print those stuff
ID: [ARRAY(0x31fcac4)] Name: [ARRAY(0x31fca84)]
ID: [ARRAY(0x31fcac4)] Name: [ARRAY(0x31fca84)]
...


if i make the @language is reference.
Expand|Select|Wrap|Line Numbers
  1.  
  2.         @return=[@language] ;
  3.  
  4.                         foreach my $current(@return){
  5.                         my $id = $current->id();
  6.                         my $name = $current->name();
  7.                         print "ID: [$id]  Name: [$name] \n";
  8.                         }
  9.                 }
  10.  
it will give me an error is
"Can't call method "id" on unblessed reference at C:/user/...."



Please help

Thank so very much
Feb 22 '11 #1

✓ answered by miller

Quick advice, don't use $db->selectall_arrayref(..sql..) unless you're more familiar with perl and complex data structures. Instead iterate over your result solutions instead using.

Expand|Select|Wrap|Line Numbers
  1. my $sth = $db->prepare("select languageId, languageName from language");
  2. $sth->execute or die $db->errstr;
  3.  
  4. while (my ($id, $name) = $sth->fetchrow_array) {
  5.     print "$id, $name\n";
  6. }
As for your other issues, I can't understand your code and your problem as it stands right now.

- Miller

PS
Enclose your code in [code]your code here.[/code] tags

1 2017
miller
1,089 Recognized Expert Top Contributor
Quick advice, don't use $db->selectall_arrayref(..sql..) unless you're more familiar with perl and complex data structures. Instead iterate over your result solutions instead using.

Expand|Select|Wrap|Line Numbers
  1. my $sth = $db->prepare("select languageId, languageName from language");
  2. $sth->execute or die $db->errstr;
  3.  
  4. while (my ($id, $name) = $sth->fetchrow_array) {
  5.     print "$id, $name\n";
  6. }
As for your other issues, I can't understand your code and your problem as it stands right now.

- Miller

PS
Enclose your code in [code]your code here.[/code] tags
Feb 22 '11 #2

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

Similar topics

7
by: crazy | last post by:
Hi It seems something really simple, but can't figure out. It's not my homework :), was just looking at some C problems on the web and came across this one. why doesn't the following code print...
4
by: Arif | last post by:
I C# code prints very slow as compared to a third party barcode printing software. That software prints approximately 10 labels in 2 seconds while my C# code prints 10 labels in 5 to 6 seconds. And...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
4
by: Charles | last post by:
I'm trying an example from the book "Learning PHP5" but it doesn't work as Expected. Snippet: <form method="POST" action="index.php"> <select name="lunch" multiple> <option value="pork">BBQ...
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
22
by: bela | last post by:
Hello, I am very new to JAVA. I would like to know, how to read *.csv file from java and how to save that data into an array. regards, bela
8
by: virkof | last post by:
Hi everyone... I am very stuck here trying to print from an Array. Can somebody help please? Basically I have two different classes, one, which creates Tickets Objects. Each object is an array of...
6
by: backups2007 | last post by:
I have an array of values that come from a database. I used a FOR loop to retrieve each of the values and pass it on to text fields. But the instead of displaying the whole word, only the first...
5
by: kkshansid | last post by:
plz help as my code is not running. its not printing array <?php $i=1; $j=0; $pidarray=array(); while($i<10) { $pidarray=$i; $i++;
1
by: sixtyfootersdude | last post by:
Good Morning! I am a perl newbie and I think that I am struggling with references. I have an array of references to hashes which I am trying to print. This is what I have: for(my...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
1
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...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.