> -----Original Message-----
> From: John W. Krahn [mailto:[EMAIL PROTECTED]]
> Subject: Re: "Use of uninitialized value" error message
> 
> Jason Larson wrote:
> > 
> > I'm still new to Perl myself, so I can't tell you exactly 
> what's happening,
> > but it looks like $result_value1 is undef when it gets to 
> the if statement.
> > I think a better way to accomplish what you're trying to do 
> is simply:
> > 
> >   my $result_value1;
> >   if ($result_value) { #$result_value1 is defined
>     ^^^^^^^^^^^^^^^^^^                      ^^^^^^^
> This is _NOT_ testing whether $result_value1 is defined or 
> not (in fact
> it is not testing $result_value1 at all :-), it is testing whether
> $result_value1 is true or false which is not the same thing.
> 
>    if ( defined $result_value1 ) { #$result_value1 is defined
> 
Doh!  My bad...  You are, of course, correct.  Thanks for pointing out my
error.
(for any beginners reading this that may not understand the difference, let
me give a quick example...)
 use warnings;
 use strict;
 my $result_value = "0";
 if ($result_value) {
   print "\$result_value is defined and is: $result_value";
 } else {
   print "\$result_value is undefined"
 }
 __END__

This prints out "$result_value is undefined", which is obviously not true.
If we change the if statement as John pointed out, we get a better result

 if (defined $result_value) {

This prints out "$result_value is defined and is: 0", which is a better
evaluation of the variable.

Sorry about the confusion, and I hope this helps...
Jason


CONFIDENTIALITY NOTICE:

************************************************************************

The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.

************************************************************************

Reply via email to