Changeset 2398
- Timestamp:
- Nov 22, 2004, 4:38:16 PM (22 years ago)
- Location:
- trunk/doc/misc
- Files:
-
- 3 added
- 1 edited
-
Foo.pm (added)
-
Foo.pod (added)
-
foo.pl (added)
-
perlCodeConventions.tex (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/misc/perlCodeConventions.tex
r2381 r2398 1 %%% $Id: perlCodeConventions.tex,v 1.2 2 2004-11-17 20:51:07jhoblitt Exp $1 %%% $Id: perlCodeConventions.tex,v 1.23 2004-11-23 02:38:16 jhoblitt Exp $ 2 2 \documentclass[panstarrs]{panstarrs} 3 3 … … 185 185 e.g. for file \file{foo.pl}: 186 186 187 \scriptsize 188 \code{#!/usr/bin/perl}\\ 189 \\ 190 \code{# Copyright (C) 2004 Joshua Hoblitt}\\ 191 \code{#}\\ 192 \code{# $}\code{Id$}\\ 193 \normalsize 194 \begin{verbatim} 195 use 5.008005; # optional 196 197 use strict; # not optional 198 use warnings; # not optional 199 200 use Foo qw( $bar ); # import $bar into our namespace 201 202 use constant MAXFOO => 3; # maximum number of foos 203 204 my $baz; # is a lexical variable in the top level scope 205 206 sub fuu 207 { 208 209 } 210 211 __END__ 212 213 ... 214 \end{verbatim} 187 \verbatiminput{foo.pl} 215 188 216 189 \subsubsection{Perl Modules} … … 261 234 e.g. for file \file{Foo.pm}: 262 235 263 \scriptsize 264 \code{# Copyright (C) 2004 Joshua Hoblitt}\\ 265 \code{#}\\ 266 \code{# $}\code{Id$}\\ 267 \normalsize 268 \begin{verbatim} 269 package Foo; 270 271 use 5.008005; # optional 272 273 use strict; # not optional 274 use warnings; # not optional 275 276 use base qw( Baz ); # become a subclass of Baz 277 278 use Foo qw( $bar ); # import $bar into our namespace 279 280 use constant MAXFOO => 3; # maximum number of foos 281 282 my $baz; # is a lexical variable in the top level scope 283 284 sub fuu 285 { 286 287 } 288 289 1; 290 291 __END__ 292 \end{verbatim} 236 \verbatiminput{Foo.pm} 293 237 294 238 \subsubsection{Plain Old Documentation} … … 300 244 e.g. for file Foo.pod: 301 245 302 \begin{verbatim} 303 =pod 304 305 =head1 NAME 306 307 Foo - Does something with Baz. 308 309 =head1 SYNOPSIS 310 311 use Foo; 312 313 ... 314 315 =head1 DESCRIPTION 316 317 More details about what this modules does with Baz. 318 319 =head1 USAGE 320 321 =head2 Import Parameters 322 323 This module accepts no arguments to it's C<import> method and exports no 324 I<symbols>. 325 326 =head2 Methods 327 328 =head3 Class Methods 329 330 =over 4 331 332 =item * methodOne 333 334 details of methodOne 335 336 =item * methodTwo 337 338 details of methodTwo 339 340 ... 341 342 =back 343 344 =head1 SUPPORT 345 346 Where to get help. 347 348 =head1 AUTHOR 349 350 Principle authors and contact info. 351 352 =head1 COPYRIGHT 353 354 Copyright (C) 2004 Robert Lupton. All rights reserved. 355 356 This program is free software; you can redistribute it and/or modify it under 357 the terms of the GNU General Public License as published by the Free Software 358 Foundation; either version 2 of the License, or (at your option) any later 359 version. 360 361 This program is distributed in the hope that it will be useful, but WITHOUT ANY 362 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 363 PARTICULAR PURPOSE. See the GNU General Public License for more details. 364 365 You should have received a copy of the GNU General Public License along with 366 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 367 Place - Suite 330, Boston, MA 02111-1307, USA. 368 369 The full text of the license can be found in the LICENSE file included with 370 this module, or in the L<perlgpl> Pod as supplied with Perl 5.8.1 and later. 371 372 =head1 SEE ALSO 373 374 L<Bar::Baz> 375 376 =cut 377 \end{verbatim} 378 246 \verbatiminput{Foo.pod} 379 247 380 248 %------------------------------------------------------------------------------ … … 643 511 \subsection{Initialization} 644 512 645 Try to initialize local variables where they're declared. Do not init alize513 Try to initialize local variables where they're declared. Do not initialize 646 514 variables with an empty string or list - this is pointless. 647 515 … … 1180 1048 \end{verbatim} 1181 1049 1050 \subsection{\$\_} 1051 1052 Use of the ``default'' variable (\code{$_}) should be avoided. 1053 1054 \begin{verbatim} 1055 my $foo =~ /(foo.*)/; # Correct 1056 foreach my $foo (@bar) {} # Correct 1057 /(foo.*)/; # AVOID! 1058 $_ = ~/(foo.*)/; # AVOID! 1059 \end{verbatim} 1060 1061 \subsection{FileHandles} 1062 1063 Don't use ``bare-words'' as filehandles except for \code{STDIN}, \code{STDOUT}, 1064 or \code{STDERR}. 1065 1066 \begin{verbatim} 1067 open(STDOUT, '>', $foo) or die "can not open STDOUT: $!"; # Correct 1068 open(my $fh, '>', $foo) or die "can not open file $foo: $!";# Correct 1069 open(FILE , '>', $foo) or die "can not open file $foo: $!"; # AVOID! 1070 \end{verbatim} 1071 1072 \subsection{System Calls} 1073 1074 Always check the return code of system calls. 1075 1076 \begin{verbatim} 1077 open(my $fh, '>', $foo) or die "can not open file $foo: $!"; # Correct 1078 close($fh) or die "can not close file $foo: $!"; # Correct 1079 chdir($foo); # AVOID! 1080 \end{verbatim} 1081 1182 1082 %------------------------------------------------------------------------------ 1183 1083 \appendix %Begin Appendices … … 1199 1099 1200 1100 \code{pertidy} is a Perl specific code ``beautifier'' with functionality 1201 similar to \code{indent} or \code{astyle}. It is freely ava lible from1101 similar to \code{indent} or \code{astyle}. It is freely available from 1202 1102 \code{http://perltidy.sourceforge.net/}. 1203 1103 … … 1205 1105 \file{.perltidyrc} file in your home directory. 1206 1106 1207 Example \file{.perltidyrc} file to ach eive the Perl code convention:1107 Example \file{.perltidyrc} file to achieve the Perl code convention: 1208 1108 1209 1109 \verbatiminput{.perltidyrc}
Note:
See TracChangeset
for help on using the changeset viewer.
