in reply to while (scalar()
Perhaps when you downloaded the script (or when it was uploaded) a less-than (<) got mistaken for the start of an HTML tag? Download again and make sure what you downloaded runs properly. I suggest you pertidy the script before you start tweaking it.
--
LP^>
|
|---|