in reply to Re: Operation `bool': no method found, argument in overloaded package Vector2D at
in thread Operation `bool': no method found, argument in overloaded package Vector2D at

I see I need to do this in my Vector2D package ...
use overload "-" => \&minus, "+" => \&plus, "*" => \&mult, "bool" => \&bool; sub bool { my $object = shift; return !undef($obj); }
... or I am more clueless than you thought :)

Thanks!
  • Comment on Re: Re: Operation `bool': no method found, argument in overloaded package Vector2D at
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Operation `bool': no method found, argument in overloaded package Vector2D at
by theorbtwo (Prior) on Jan 24, 2002 at 08:57 UTC
      What was I thinking ...

      I meant ...
      sub bool { return defined (shift); }
      ... I think? Right?

      Why don't I just run it and find out!
      Thanks again

        Well, that does what you think it does, probably. If the object you're trying to determine the truth of is defined, then this will return a true value, and the Vector2D will thus be considered true.

        However, consider for a moment under what circumstances this will return false.

        defined() returns false only if it's argument is undef. However, undef isn't-a Vector2D, so your bool() function will never get called on undef.

        You method, in other words, is equivilent to sub bool {return 1;} (golfers note: in all of these examples, the return and semicolon are optional. I find that confusing, so don't use it.).

        Think about what the semantics of truth for a Vector2D are, then write your function.

        (BTW, I don't mean for this to sound snippy or anything, I'm just in a kind of off mood.)

        TACCTGTTTGAGTGTAACAATCATTCGCTCGGTGTATCCATCTTTG ACACAATGAATCTTTGACTCGAACAATCGTTCGGTCGCTCCGACGC