By the way, you have if($num_data_on eq 0) which should probably be if($num_data_on == 0) The eq operator should be used for string comparisons, not numeric.
Also, while I am at it, @date_array[2] is better written as $date_array[2]. The leading $ or @ indicates the context of the index, use $ when you are using a single array element, and @ when you want a list of several elements.