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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

prakashk021799Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
Where does $zeile come from?  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.