Thank you Dave for going through the code in such details. Based on your suggestion, I have made one more modification, i.e. using 0 instead of "" when initializing $previous, since the $arr
FIELD0 is numeric too. I will run the script and hopefully everything will be fine. :)