http://www.perlmonks.org?node_id=832120


in reply to Re^2: Repeating Code - there has GOT to be a better way!
in thread Repeating Code - there has GOT to be a better way!

Great. It's best to restrict it to the smallest possible scope. Having it at the top makes it, more or less, a global which can be seen or persist anywhere in the script. This can lead to lame/long debugging sessions. Better to put it inline with the loop.