Carnivores that spray foul anal secretions might have evolved this ability in response to night-time predation from other mammals.

Theodore Stankowich at California State University in Long Beach and his colleagues looked at the behaviour of 181 species of carnivorous mammals and their predators. The authors found that carnivores are targeted mainly by other mammals at night and by birds of prey during the day. Animals that are active during the day are more likely to develop tight-knit social groups that are better at detecting and warding off predators.

Nocturnal animals cannot rely on early visual detection and instead use short-range defence systems such as noxious sprays, which are more effective against other mammals than against birds.

Evolution http://doi.org/q9w (2014)