in reply to adding/subtracting calender dates

A good way to comfort yourself is to design some tests, but in this case, you are laboriously reinventing a wheel that's likely to leave you with buggy code. Try DateTime or Date::Manip or Date::Calc.

By the way, I don't think xor does what you think it does.

Replies are listed 'Best First'.
Re^2: adding/subtracting calender dates
by Fuism (Beadle) on Jun 02, 2005 at 19:13 UTC
    Hmmm well it seemed to work like I wanted. Please let me know what you think it does. It would be great to know what it really does as to what I think it does. Thanks again... Fue
    xor =
    by hubb0r (Pilgrim) on Jun 02, 2005 at 20:50 UTC
      FYI - xor is an "exclusive or". It has the following rules:
      (1 xor 1) == 0 (1 xor 0) == 1 (0 xor 1) == 1 (0 xor 0) == 0 (0 xor 1 xor 1) == 0 (0 xor 1 xor 0) == 1 etc etc
      Meaning that it will return true if and only if exactly 1 of the xor'd variables returns true.

        Close, but not quite. Try this for example:

        print "foo" if (1 xor 1 xor 1);

        prints foo, since

        (1 xor 1 xor 1) == ((1 xor 1) xor 1) == ( ( 0 ) xor 1 ) == 1

        In general terms, xor actually returns true if an odd number of true values exist in the set. In the cases where the set is of size two, this means exactly one truth. That doesn't generalize, though.

        addendum: In the OPs case, though, it worked because his alternatives were all mutually exclusive. However, since xor can't shortcircuit, it took a lot longer to work than a normal or.