Re: very strange conditional problem

From: J. Romano (jl_post_at_hotmail.com)
Date: 02/21/04


Date: 21 Feb 2004 08:14:52 -0800

Kodeguru <newz@xoftware.org> wrote in message news:<2SGZb.27067$ac.4342902@news4.srv.hcvlny.cv.net>...
>
> # this line prints $equip_row->[16] is (some@email.address)\n
> # which is right
> print "\$equip_row->[16] is ($equip_row->[16])\n";
>
> if ($equip_row->[16] != undef){ # But then this test fails
>
> # and this line doesn't print at all
> print "$equip_row->[16] is not undef, so...\n";
>
> #####------######
>
> Now if I change the line where the conditional is to
>
> if ($equip_row->[16] =~ /\S+/) {
>
> It works. Both debug lines print like they should and the emails get sent.
>
> Anyone else have any ideas ?

   I have an idea, even though I do not know the exact reason why your
code is not working as you'd expect.

   My thought is that your Perl interpreter doesn't like comparing a
scalar to undef. Therefore, I suggest that, instead of comparing a
scalar to see if it doesn't equal undef, try seeing if it is defined
by using the "defined" keyword. Try changing the condition:

   if ($equip_row->[16] != undef)

to this one:

   if (defined($equip_row->[16]))

   See if that works.

   Happy Perling!

   -- Jean-Luc



Relevant Pages

  • Re: very strange conditional problem
    ... Both debug lines print like they should and the emails get sent. ... My thought is that your Perl interpreter doesn't like comparing a ... scalar to see if it doesn't equal undef, try seeing if it is defined ...
    (comp.lang.perl)
  • Re: set of a set etc.
    ... assuming x is a scalar... ... Now and } are both sets and when comparing them their elements ... coincidence that each successor contains its predecessor, ...
    (sci.math)
  • Re: Comparing fp types for equality
    ... Do the same issues involved in comparing 2 fp types for equality ... The macro normalizes the difference between scalar a and scalar b regarding ...
    (comp.lang.c)
  • Re: Comparing fp types for equality
    ... Do the same issues involved in comparing 2 fp types for equality ... The macro normalizes the difference between scalar a and scalar b regarding ...
    (comp.lang.c)