I have a matcher that looks through a number of objects and returns the first that matches certain criteria or - if none are found - it returns undef.
Now all I need to know is if the resulting variable is defined or not. As I expect the object to be defined, I croak if no object was found.
So far the theory. Here is the code:
my $ls = Obj::LocationSource->new(); my $dep_tip = $ls->match( { location => $dep_name } ); print Dumper( $dep_tip ); if ( ! defined $dep_tip ){ croak ( "DATA ERROR: Could not find any location for '$dep_name'" ); } OUTPUT: $VAR1 = bless( { '_location' => 'Salisbury', '_id' => 259, '_key' => 'SLSBRY' }, 'Object::Location' ); DATA ERROR: Could not find any Location for 'Salisbury' at ***.pl line + 45
I do not understand why ! defined $dep_tip seems to evaluate to true.
Considered by PerlingTheUK: Please delte as I found the error in a later line in the code.
Unconsidered by planetscape: keep (and edit) votes prevented reaping
In reply to Definedness of an Object by PerlingTheUK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |