473,508 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

warning in Push statement.

25 New Member
Hi
I am trying to Push one line at a time from three different arrays into a new array
Here is a part of the code that is giving trouble:

Expand|Select|Wrap|Line Numbers
  1.      my @result_line;
  2.  
  3.      while ($entries >=  0 ){
  4.      @result_line = ();
  5.      push @result_line, $result_line1[$entries];
  6.      push @result_line, $result_line2[$entries];
  7.      push @result_line, $result_line3[$entries];
  8.      print "@result_line\n";
  9.      $entries--;
  10.  }

The code gets compiled with rest of the code and also gives me proper result But I am getting following (warning) message each time it loops through the while loop:

Use of uninitialized value in join or string at search_IP.plx (for the line with the Print statement)

I have initialized the array @result_line then why is it happening?
Please help.
Thanks
Nov 27 '06 #1
4 1474
GunnarH
83 New Member
why is it happening?
Because you push() one or more undefined values into @result_line.

If that's not help enough, please post a short but complete program, that we can copy and run, and that demonstrates the issue.
Nov 27 '06 #2
Studentmadhura05
25 New Member
Hi,
I did not paste the lines where I have aleady declared and initialized the arrays that i am pushing.

Expand|Select|Wrap|Line Numbers
  1. my @result_line1 = grep (/lease/, @result);
  2. my @result_line2 = grep (/starts/, @result);
  3. my @result_line3 = grep (/ends/, @result);
  4.  
  5. while ($entries >=  0 ){
  6.      @result_line = ();
  7.      push @result_line, $result_line1[$entries];
  8.      push @result_line, $result_line2[$entries];
  9.      push @result_line, $result_line3[$entries];
  10.      print "@result_line\n";
  11.      $entries--;
  12. }
Actually there is no array or variable that is not initialized. Please help.
Nov 28 '06 #3
GunnarH
83 New Member
That's still not a complete program.

It's not about a variable, but at least one element in @result_line is undefined.
Expand|Select|Wrap|Line Numbers
  1. C:\home>type test.pl
  2. use warnings;
  3. my @array = ('blue', undef, 'yellow');
  4. print "@array\n";
  5.  
  6. C:\home>test.pl
  7. Use of uninitialized value in join or string at C:\home\test.pl line 3.
  8. blue  yellow
  9.  
  10. C:\home>
Nov 28 '06 #4
miller
1,089 Recognized Expert Top Contributor
Just because the arrays are initialized, does not mean that the scalar elements that you are trying to access are also initialized:

Expand|Select|Wrap|Line Numbers
  1. my @result_line1 = grep (/lease/, @result);
  2. my @result_line2 = grep (/starts/, @result);
  3. my @result_line3 = grep (/ends/, @result);
  4.  
  5. warn "badness1" if $entries > $#result_line1;
  6. warn "badness2" if $entries > $#result_line2;
  7. warn "badness3" if $entries > $#result_line3;
  8.  
Nov 28 '06 #5

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

Similar topics

6
23184
by: Will | last post by:
Hi, Sorry to be a pest... But I can figure this out. I'm pushing to a stack. then I need to check to see if the word is a palindrome. Is the code below correct? if so, how can I check the...
5
2492
by: Adrian | last post by:
Hi all, I am getting a warning compiling the following code using Borland C++ Builder 6, but I dont think I am doing anything wrong. When using g++ I get no warnings at all with a g++ -Wall...
29
2481
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
2
31608
by: Siemel Naran | last post by:
I keep getting warning messages like these: ....\include\myfile.h(451) : warning C4251: 'MyClass::m_myvariable' : class 'CPtrArray' needs to have dll-interface to be used by clients of class...
10
1665
by: Rich Sienkiewicz | last post by:
The C# compiler gives warnings about unused variables. I thin it needs a warning about an unassigned reference. For instance, this compiles without any warnings/errors, but of course blows up when...
8
1989
by: Charles Sullivan | last post by:
I have a program written in C under Linux (gcc) which a user has ported to run under AT&T SysV R4. He sent me a copy of his makelog which displays a large number of compiler warnings similar to...
5
5074
by: Peter Ritchie [C# MVP] | last post by:
I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time. I've just recently had the cycles to investigate the warning. The warning message...
27
3093
by: Terry | last post by:
I am getting the following warning for the below function. I understand what it means but how do I handle a null reference? Then how do I pass the resulting value? Regards Warning 1...
3
8020
by: ashnin | last post by:
Hi, Can anyone tell me, why am I getting this warning? cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++ (Actually Im compiling a set...
0
7229
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,...
0
7129
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
7398
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...
1
7061
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
7502
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...
0
5637
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,...
0
4716
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
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
428
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...

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.