in reply to uninitialized values

Your arrays @values2 and @val2 and the scalar $val are never used, so let's remove them for now.

The main problem is that your assignment to zero is almost certainly not doing what you want. It is setting @values1 to (0) and @val1 to undef. When the "if" expression is false, those values are not changed and so what you are attempting to print is undefined - hence the warning. To illustrate, try changing your loop like this:

while (<CMD>) { my (@values1) = ('Not set', 'Really not set'); my (@val1) = ('Nothing here', 'Nor here'); # Nothing changed below here if ( $_ =~ /PING/ ){ @values1 = split ; @val1 = split(/\(/,$values1[3]); $val1[1] =~ s/\)//; } print "$values1[1] \n"; print "$val1[0] \n"; }

I would also very strongly urge you to get into the habit of choosing meaningful names for your variables. @values1, @val1, @values2, @val2 and $val are all very similar and equally meaningless and this really adds to the confusion of the code.

Good luck.

Replies are listed 'Best First'.
Re^2: uninitialized values
by gaurav (Sexton) on Aug 19, 2013 at 13:40 UTC

    Sorry ,for variable names & am very thankful to you for pointing that out to me.But my problem is remain same that I want to use those print stmt. outside if block,please help me on this

      ... I want to use those print stmt. outside if block ...

      The code example of hippo defines and initializes the lexical  @values1 and  @val1 arrays outside the if-block and then uses them both inside and outside the block. Please take another look at this example and see if things make more sense.

      I should ask that what I have to do to avoid that warning