I didn't mean to re-use the variable name. What happened is that originally I was just using it in the inner scope, and then when I started realizing I needed it in the outer scope, I forgot to remove the initialization from the inner scope.
And one clarification; probably a mistaken simplification on my part in my example. I was using $pkgname::usefuldata
in my code, not just a plain $usefuldata... something I resorted to when trying to move a cron script I created into a web application.
So really, to avoid this in the future, I have to write and keep rewriting my code to use 'my' all the time, rather than expecting some compile time or run-time checking to warn me. Is that basically right?