in reply to A question of style - declaring lexicals
I've just spent some time making changes to an app that I wrote a year ago (always fun!).
I discovered that within subroutines that spanned up to a couple of screens' depth, I had declared all variables used within the subroutine, right at the top of it.
I didn't like it at all, as I had to keep scrolling up to see if something had already been assigned to.
I think now I tend to declare a var when it's first used, with the following exceptions:
Loop vars are declared at the start of the loop,
Package vars in modules are declared right at the top of the file.