You should probably check split() has returned a non-empty list.