error message: local variable in a subroutine is not initialised

I have defined a subroutine with a local variable. The local variable is a list. The compilation it isn't correct,its follow the error message:

"Use of unitialized value".

Here are the code

sub dat {
my @result_tmp;
open(T,"<$$QLRESULT");
$anz=0;
while($zeile=~m/ORA_VERSION/){
     chomp($zeile);
     $result_tmp[$anz]=$zeile;
     $anz=$anz+1;}
 close(T);
if ($result_tmp[0] eq "")#error-message
{ do something;}
}


spetrowitschAsked:
Who is Participating?
 
prakashk021799Connect With a Mentor Commented:
It is possible in your code for the while loop to have exited without filling in the array @result_tmp. In such case, $result_tmp[0] is not defined.

If you want the warning to go away, change the offending line to this:

if (defined $result_tmp[0] and $result_tmp[0] eq "") {
    # do something
}


If you just want to know if the array is empty, a better way to check that would be:

unless (scalar @result_tmp) {   # array is empty
    # do something
}
0
 
ozoCommented:
Where does $zeile come from?  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.