# 0. Just-in-time variable declaration and initialization. #### # 1. Variables in consistent case (all lower or all upper) # 2. Each dictionary word in the variable name separated # by underscore, unless accepted as one word by usage as # in 'username' or 'logout' # 3. Package variables in all caps, used for things like # config values use vars qw( $FOO $BAR $BAZ $FOO_BAR ); #### # 4. Global lexicals in all lower case, and # prefixed with some text to mark them as such. # For example... my ($glob_foo, $glob_bar, $glob_baz, @glob_foo_bar); #### # 5. Local lexicals on all lowercase sub foo { my ($bar) = @_; for (@$bar) { print "yay" if ($_ eq $FOO); } return $bar; } #### # 5.5. Use prefixes to scope other logically different # vars. For example, 'cgi_' to prefix vars holding # params delivered via the cgi my $cgi_foo = $cgi->param('foo'); my $cgi_bar = $cgi->param('bar'); # 6. Refs prefixed with the appropriate identifier. I wish # Perl would extend the "different things look different" # to enable easy identification of the kind of data # structure a ref refers to. my $aref_bar = foo(\@foo_bar); # 7. Rules 1-5 apply to rule 6 as well... so, an array ref # inside a sub would be $this_aref_bar, etc. #### # 8. modified: I like camelCase, however, the real purpose # here is to visually distinguish a sub from a var. Choose # your method # 9. Subroutines not exported from a package prefixed with # an underscore package Foo; @EXPORT = qw( startProgram watchOut goHome ); sub startProgram { _wakeUp(); } sub watchOut { _keepEyeOpen(); } sub goHome { _nightyNight(); } sub _wakeUp {} sub _keepEyeOpen {} sub _nightyNight {} # 9.5. Never export anything by default. @EXPORT_OK #### # 10. Always pass named vars to subs doThis('with' => $that, 'and' = $something_else);