All,

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.


Cheers,
PerlingTheUK

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.