I've never forgotten to pack a flashlight, probably because I just keep one in my camera bag. However, I have had them die variously untimely deaths. Thus, I have bought flashlights in places like Zimbabwe and Fiji. Inevitably, one can only buy huge D-battery using ones, instead of the nice miniature ones I typically favor. I've now taken to packing a second flashlight. That practice saved me from having to buy one in Madagascar. Somewhat surprisingly, I never had to use either flashlight on my recent trip to Cambodia and Thailand.
As for hats, they are easily obtained, though I do usually manage to remember to pack one. But hats pose a different kind of packing problem because I have an odd superstition regarding them. I consider it horribly bad luck for my hat to ever come into any sort of contact with my bed. Since I tend to put my bag on my bed when I'm packing, this can be rather inconvenient. I know this is entirely absurd, but we are all entitled to a few harmless quirks.
There is a seed of a story in all of this, which will probably not germinate for several months.