12 (13?) years ago I had also written a Naïve Bayes classifier in Perl https://github.com/cipherself/NaiveBayes_perl

IIRC, next thing on my TODO list was to add vectorization. Also (like OP) it uses log probabilities to avoid floating-point underflow.