Re-reading this post, I see it's not very clear.

This line is in error
$flavor != CAT_TO_CAT) &&

because of the extraneous bracket before the logical and.