Ya know, I served in the military, and I didn't understand that concept then, and I don't understand it now? Whats up with no hats indoors? And even moreso when talking to a woman? Quite frankly, that is probably the most oudated, archaic idea I've seen/heard/read in a long time. Makes no sense whatsoever, lol
The whole "doff your hat while talking to a woman, a group of women, or a man escorting a group of women" thing is pretty darn archaic and useless in modern social convention (in fact, it's kind of creepy).
The inside thing is just common sense. Hats are worn due to the weather, so you take them off when you take your coat of. Etiquette grew along those lines, and this is still relevant today, so it's a respectable thing to do.
Honestly, I'd just not wear the hat. 99% of people don't look cool while wearing hats. The ones that do look just as cool without.