Hi all,
Im trying to print ARRAY OF ARRAYS using following code. -
for $i (0..10) {
-
print "\t [ @{$myvar[$i]} ] ,\n";
-
}
-
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.
8 28604 KevinADC 4,059
Recognized Expert Specialist
do this: - for $i ( 0 .. 10 ) {
-
print "$i = $myvar[$i]\n"
-
#print "\t [ @{$myvar[$i]} ] ,\n";
-
}
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.
do this: - for $i ( 0 .. 10 ) {
-
print "$i = $myvar[$i]\n"
-
#print "\t [ @{$myvar[$i]} ] ,\n";
-
}
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 )
KevinADC 4,059
Recognized Expert Specialist
try this then: - for $i ( 0 .. 10 ) {
-
print "$i = $myvar[$i]\n"
-
print "\t [ @{$myvar[$i]} ] ,\n";
-
}
and see how far it gets before printing the error message.
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. -
for $i (0..$#myvar) {
-
print "\t [ @{$myvar[$i]} ] ,\n";
-
}
-
should fix the problem, since you're only looping through those elements which exist.
KevinADC 4,059
Recognized Expert Specialist
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. -
for $i (0..$#myvar) {
-
print "\t [ @{$myvar[$i]} ] ,\n";
-
}
-
should fix the problem, since you're only looping through those elements which exist.
Good observation lukertin.
But doesn't perl just put in null equivalents?
numberwhun 3,509
Recognized Expert Moderator Specialist
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
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 - for $i (0..10) {
-
if (exists @{$myvar[$i]})
-
{
-
print "\t [ @{$myvar[$i]} ] ,\n";
-
}
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 two";
examlpe="example three";
|
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 in my code
(I could have made a library instead of a class).
I can't find out why g++ compiles fine, but does not link correctly
the following code. Here, I am posting my full code, .h and .cpp just
to make all things clear.
The linker output...
|
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
|
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 is to improve, but not to prove.
|
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
visible to a client using a browser. My question is...can a
knowledgeable browser user view Jscript source code in an asp file?
| |
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; i++);
group=new Array();
|
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 the html page
controls the form fields that are required. It doesn't function like
it's supposed to and I can leave all the fields blank and it still
submits the form. Also I can't get it to transfer the file in the
upload section. The file name...
|
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 instance of an object.
Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if there
are no numbers the debugger shows it as <undefined value>. But other fields
|
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 there is a checkbox (v1) allowing to select that row
for changes (e.g. delete, update, etc.)
So we are creating an array of checkbox, correct ?
Of course I have to check whether any of these checkboxes exist and if any
of them got selected (checked)
|
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: 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: 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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |