Having read the conversation so far, maybe I can help shed some light on the issue you face. It seems your root concern is that you pick-and-mix code from other places and are concerned that variables picked up along the way may cause the resultant patchwork code to behave badly.
So the first thing is use strict; use warnings; are your friend. As a general thing Perl's scope rules (where an identifier refers to the same thing) are pretty sane. That in combination with strictures will pretty quickly weed out most badness. There are a couple of particular cases to think about:
- If you paste in a sub then none of the variables in the sub can "leak" into the surrounding code.
- If you paste in a block of code you can wrap it in {...} and guarantee that none of the variables can "leak" into surrounding code.
- If strictures throw up errors then most likely code somewhere wants Global variables. Global variables should be avoided where possible because they tend to contribute to hard to maintain code.
- Restrict variable to the smallest scope (set of {}) that makes sense.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond