This is an interesting question. While entirely uncertain if i have the best coding policy, usually i break it down this way:
- Localize $_ on every subroutine/method that uses $_ where it's not implicitly localized for you
- Localize $_ on every subroutine/method where it's ambiguous whether $_ will be localized for you or not.
- Use a variable for every foreach that calls other subroutines/methods in its body.
- Use a variable if there's the possibility that $_ will be used (explicit or implicit) and possibly clobbered in a foreach.
- Always check to make sure your values are where you left them, don't assume $_ will be localized for you!
Note how i localize $_ in subroutines whether i know it's going into a loop structure or not. This assures i'm not taken by surprise when i have to add an extension because my manager didn't tell me all the specs to start with :)
These are just my personal habits, i'd be happy to hear other monks outlook on the matter as well.
Hope This Helps,
jynx