in reply to Naming convention for variables, subroutines, modules, etc.. and variable declaration

Naming

Damian discusses some techniques in Perl Best Practices. Larry has some advice in perlstyle.

There are various naming conventions you can use, and don't restrict yourself to Perlville to find one that makes sense for you and what you are doing.

Other monks probably will chime in with more advice, and I'm off to eat thanksgiving turkey or I'd think about this more. Good luck :)

Declarations

I tend to define the lexical variables as late as possible and as close to their use as possible, as in your first example. This limits the effect of the variable to exactly the scope I want to use it. If I need it in some other scope, I just declare it again.

Declaring variables upfront tends to give variables a larger scope than they really need. You might do that as a way to start introducing lexical variables into a script that only used package variables, but only while you waited for the time to convert them to your first form.

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review
  • Comment on Re: Naming convention for variables, subroutines, modules, etc.. and variable declaration
  • Select or Download Code