Section 2.3. Subroutines and Variables


2.3. Subroutines and Variables

Don't separate subroutine or variable names from the following opening bracket.

In order for the previous rule to work properly, it's important that subroutines and variables not have a space between their names and any following brackets. Otherwise, it's too easy to mistake a subroutine call for a control structure, or misread the initial part of an array element as an independent scalar variable.

So cuddle subroutine calls and variable names against their trailing parentheses or braces:

      my @candidates = get_candidates($marker);     CANDIDATE:     for my $i (0..$#candidates) {         next CANDIDATE if open_region($i);         $candidates[$i]             = $incumbent{ $candidates[$i]{region} };     } 

Spacing them out only makes them harder to recognize:

     my @candidates = get_candidates ($marker);     CANDIDATE:     for my $i (0..$#candidates) {         next CANDIDATE if open_region ($i);         $candidates [$i]             = $incumbent {$candidates [$i] {region}};     } 



Perl Best Practices
Perl Best Practices
ISBN: 0596001738
EAN: 2147483647
Year: 2004
Pages: 350
Authors: Damian Conway

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net