[ale] undef problem.

Fletch fletch at phydeaux.org
Fri Dec 3 09:43:12 EST 2004


>>>>> "Christopher" == Christopher Fowler <cfowler at outpostsentinel.com> writes:

    Christopher> Can someone tell me what is wrong with the following
    Christopher> code?  $self->{'CONNECTION'}->disconnect(); undef
    Christopher> $self->{'CONNECTION'}; print "connection is not
    Christopher> undef\n" unless $self->{'CONNECTION'};

    Christopher> It seems that The message it printed out.

As it should since you print if $self->{CONNECTION} is false ('unless
EXPR' is just syntactic sugar for 'if !(EXPR)').  The undef stores
undef in the hashref for that key (which is false in boolean context),
so you've basically got 'EXPR if !$self->{CONNECTION}' which will
always run since you've just set it to a false value.


Perhaps you mean:

print "connection is not undef\n" if defined $self->{CONNECTION};


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list