473,382 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Can't use an undefined value as an ARRAY reference

34
Hi all,

Im trying to print ARRAY OF ARRAYS using following code.

Expand|Select|Wrap|Line Numbers
  1. for $i (0..10) {
  2.     print "\t [ @{$myvar[$i]} ] ,\n";
  3. }
  4.  
But it is giving following error.

Can't use an undefined value as an ARRAY reference at perl23.plx line 18.

Please help me to solve this problem.
Apr 23 '07 #1
8 28461
KevinADC
4,059 Expert 2GB
do this:

Expand|Select|Wrap|Line Numbers
  1. for $i ( 0 .. 10 ) {
  2.    print "$i = $myvar[$i]\n"
  3.    #print "\t [ @{$myvar[$i]} ] ,\n";
  4. }
and see what gets printed. Your code is not necessarily the problem, it's the data, @myvar must not be defined or some elements are not defined.
Apr 23 '07 #2
pnsreee
34
do this:

Expand|Select|Wrap|Line Numbers
  1. for $i ( 0 .. 10 ) {
  2.    print "$i = $myvar[$i]\n"
  3.    #print "\t [ @{$myvar[$i]} ] ,\n";
  4. }
and see what gets printed. Your code is not necessarily the problem, it's the data, @myvar must not be defined or some elements are not defined.
Hi kevin,

I tried with ur code but it is giving referances of arrays.

It is like

1 = ARRAY(0x814fd24)
2 = ARRAY(0x816f054)
3 = ARRAY(0x816f0cc)
4 = ARRAY(0x816f144)
5 = ARRAY(0x816f1bc)
6 = ARRAY(0x816f234)
7 = ARRAY(0x816f2ac)
8 = ARRAY(0x816f338)
9 = ARRAY(0x816f3b0)
Apr 24 '07 #3
KevinADC
4,059 Expert 2GB
try this then:

Expand|Select|Wrap|Line Numbers
  1. for $i ( 0 .. 10 ) {
  2.    print "$i = $myvar[$i]\n"
  3.    print "\t [ @{$myvar[$i]} ] ,\n";
  4. }
and see how far it gets before printing the error message.
Apr 24 '07 #4
It's his code...

the for loop goes from 0 to 10, but there are only 8 elements in the array, so it is obviously going to run into an error.

Expand|Select|Wrap|Line Numbers
  1. for $i (0..$#myvar) {
  2.     print "\t [ @{$myvar[$i]} ] ,\n";
  3. }
  4.  
should fix the problem, since you're only looping through those elements which exist.
Jun 26 '07 #5
KevinADC
4,059 Expert 2GB
It's his code...

the for loop goes from 0 to 10, but there are only 8 elements in the array, so it is obviously going to run into an error.

Expand|Select|Wrap|Line Numbers
  1. for $i (0..$#myvar) {
  2.     print "\t [ @{$myvar[$i]} ] ,\n";
  3. }
  4.  
should fix the problem, since you're only looping through those elements which exist.

Good observation lukertin.
Jun 26 '07 #6
But doesn't perl just put in null equivalents?
Sep 12 '08 #7
numberwhun
3,509 Expert Mod 2GB
But doesn't perl just put in null equivalents?
Sure, if you tell it to when you are defining the elements. But, if you are accessing them and you provide an index that isn't defined, then you will get an error.

lukertin gave a good example of how to set your limit to the number of elements in the array.

Regards,

Jeff
Sep 13 '08 #8
Hi,
In case you don't know the size or your array, you can use the "exists" function: http://perldoc.perl.org/functions/exists.html
try something like

Expand|Select|Wrap|Line Numbers
  1. for $i (0..10) {
  2. if (exists @{$myvar[$i]})
  3. {
  4. print "\t [ @{$myvar[$i]} ] ,\n";
  5. }
  6. }
Mar 1 '15 #9

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

Similar topics

14
by: Randell D. | last post by:
Folks, Here's my problem: I am createing an array in a file using the reslut of some PHP and MySQL processing. An example of my array would be examlpe="example one"; examlpe="example...
1
by: Jean-Francois Brault | last post by:
I wrote a crappy class for radian angle management. The class consists of an array of radian values. I put all these things in a class in which all methods are static, so I can access it anywhere...
48
by: marbac | last post by:
Hi, i heard a lot about "undefined behaviour" in this and other newsgroups dealing with c/c++. Is there a list where all cases with undefined behaviour in C++ are listed? regards marbac
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
6
by: amerar | last post by:
Hi All, I'm not good at Javascript, so I am trying to understand this small bit of code: var groups=document.$fm.category.options.length; var group=new Array(groups); for (i=0; i<groups;...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: tshad | last post by:
I have a structure (which happens to be a Java DataBean that contains some string arrays) that is giving me an error. The error at the "for" statement is: Object reference not set to an...
13
by: Oleg Konovalov | last post by:
Hi, I am working on a web application which among other things uses DHTML, Java and Javascript. It populates web page based on the contents of the database (resultset), and next to each row...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.