Perl Best Practices

First Edition Juli 2005
ISBN 978-0-596-00173-5
Seiten 542
EUR38.00, SFR64.90


Weitere Informationen zu diesem Buch

Inhaltsverzeichnis | Index | Probekapitel | Rezensionen |


Index

	
[ Numbers and Symbols ], [ A ], [ B ], [ C ], [ D ], [ E ], [ F ], [ G ], [ H ], [ I ], [ J ], [ K ], [ L ], [ M ], [ N ], [ O ], [ P ], [ Q ], [ R ], [ S ], [ T ], [ U ], [ V ], [ W ], [ X ], [ Y ], [ Z ],

Numbers and Symbols[ Top ]
{ } (see braces)
( ) (see parentheses)
[ ] (see square brackets)
& (ampersand), 175-177
@_ array, 178-181, 185, 470
* (asterisk), 206
\ (backslash), 52, 54, 243
# character, 236
: (colon), 31
, (comma) (see commas)
- (dash), 302, 303
$ (dollar sign), 89, 195
. (dot) operator, 355
" (double quotation) (see double quotation)
= (equals sign), 302
/ (forward slash), 243
- (hyphen), 44, 302
$ metacharacter, 237, 238, 239, 241
. metacharacter, 240
^ metacharacter, 237, 238, 239, 241
- (minus sign), 88
-> notation, 227
<> operation (see slurping)
! operator, 70, 356
** operator, 15
|| operator, 70, 185
||= operator, 185
+ (plus) operator, 356
+ (plus sign), 15
? (question mark), 31, 32, 262
<> (see angle brackets)
@ (see at sign)
$_ (see dollar-underscore)
; (see semicolons)
_ (see underscore)
' (single quotation) (see single quotation)
$/ variable, 213, 215

A[ Top ]
\A anchor, 239, 257, 470
$a variable, 74, 430
abbreviations, 46-47, 473
abs function, 106
"abstract" as ambiguous name, 48
accessors
      best practice, 479
      lvalue, 346-349
      overview, 340-346
ACKNOWLEDGEMENTS template, 139
adjectives, naming conventions, 38
algorithms, documenting, 142, 143
alias function, 104
alias variables, 104
aliases
      @_ array and, 180
      best practices, 471
      defined, 103
      dollar-underscore, 114
      each function and, 105
      in-situ files and, 305
      values function, 102
      (see also Data::Alias module; Lexical::Alias module)
aliasing, 103, 104
@alist argument, 173
all( ) subroutine, 173, 490
:ALL tagset, 410
alternations
      backtracking and, 269-271
      character classes and, 265, 266
      factoring, 266-268
      string comparisons, 271, 272
ampersand (&), 175-177
and operator, 70, 176
angle brackets <>
      bareword filehandles and, 204
      bracketing, 10
      heredocs and, 64
      as input operators, 167
      (see also slurping)
anon_scalar( ) subroutine, 330, 490
any( ) subroutine, 71, 72, 173, 490
APIs, modules and, 397
apply( ) subroutine, 173, 490
$ARG variable, 81
arguments
      best practices, 470, 479, 480
      bless function, 365-367
      capitalization of, 45
      command-line processing and, 304-305, 306
      constructors and, 367-370
      default values, 185-186
      error handling, 307
      existence tests for, 184
      fat commas and, 66
      grep function, 169
      labeled, 45, 165
      map function, 169
      methods and, 338
      missing, 184-185
      named, 182-183
      ok( ) subroutine, 422
      open statement, 207
      package variables and, 306
      parentheses and, 177
      positional, 183, 368
      return statements, 186
      sleep function, 168
      split function and, 158
      subroutine prototypes and, 194, 195
      subroutines and, 178-181
      substr function, 166
      testing considerations, 427
      unpacking list, 180
      use English pragma and, 82
      verifying, 181
*ARGV stream, 216, 219
$ARGV variable, 430
%ARGV variable, 310, 430
@ARGV variable, 74, 219, 430
array elements
      misreading, 12
      slice layouts and, 90
      vertical alignment and, 27
array indices
      best practice, 474
      overview, 88-89
      unnecessary subscripting and, 101, 102
array-ref values, 192
arrays
      anonymous, 331
      attribute demolition and, 385
      best practice, 473
      grammar rules, 39
      indices and, 88-89
      naming conventions, 43
      references to, 233
      slice factoring, 92
      slicing, 89
      unnecessary subscripting, 101-103
      unpacking @_, 178-181
      use strict pragma and, 429
arrow notation, 230
arrow syntax, 227, 228
ASCII characters
      character classes and, 248
      escaped, 54, 55
      sort function sequence, 152
assignment operator
      aligning, 53
      breaking before, 30, 31
      vertical alignment of, 26, 27
      warnings and, 431
assignments
      best practice, 473
      code layout, 30, 31
      to function calls, 165
      local declarations, 77
      lvalues and, 166
      slicing, 89, 90
      unlocalized, 81
asterisk (*), 206
at sign (@)
      hash access and, 89
      unpack function and, 156, 157
:ATTR marker, 385, 386, 387, 388
attributes
      accessing, 340-346
      best practice, 480
      building, 387, 388
      demolishing, 384-386
      encapsulation and, 328, 329
      hash-based objects and, 359
      inside-out objects and, 324, 329, 337
      lvalue methods and, 347
      unique to classes, 373
Attribute::Types module (CPAN), 488
AUTHOR template, 135
autoflushing, 224-226, 477
AUTOLOAD( ) method, 393-396, 480
$AUTOLOAD variable, 74
AUTOMETHOD( ) method, 396

B[ Top ]
$b variable, 74, 430
backslash (\), 52, 54, 243
backtracking, 269-271
barewords
      ampersand and, 176
      best practices, 470, 473
      constants and, 57
      filehandles and, 202-204
      subroutine calls and, 205
      in values and expressions, 65, 66
base 8, 54
base classes
      best practice, 480
      inheritance and, 360, 379
      initializing, 371-376
base module, 487
"bases" as ambiguous name, 48
BBEdit editor, 485
=begin/=end directives, 145, 147
Benchmark module, 456-459, 487
benchmarking
      best practices, 469, 481
      caching strategies, 463, 464
      overview, 456-459
bless function, 330, 365-367
blessed( ) subroutine, 170, 490
block form
      if keyword, 93, 94, 96
      postfix form and, 97
blocks
      any function and, 71
      best practice, 472, 474
      code layout and, 22
      grep function and, 169, 170
      map function and, 169, 170
      semicolons and, 15, 17
Boehm's Law, 4
boilerplates
      best practice, 475
      extended, 138, 139
      overview, 133-137
booleans
      best practice, 473
      Contextual::Return module, 192
      conversion subroutines for, 388
      missing arguments and, 184
      multi-contextual return values, 191
      naming conventions, 40-41
      precedence operators and, 70
:BOOLIFY method, 388
braces { }
      bracketing, 10
      as delimiters, 242-246
      empty hashes and, 374
      filehandles and, 217
      keywords and, 11
      references in, 228-229
      subroutines and variables, 12
      vertical alignment of, 27
bracketing, 9-11, 472
brackets (see braces; parentheses; square brackets)
BSD bracketing, 10, 11
BUGS AND LIMITATIONS template, 135
BUILD( ) method
      construction/destruction and, 381, 384
      cumulative methods and, 389
Build.PL, 416
built-in functions
      automating sorts, 164, 165
      best practice, 472, 475, 478
      code layout and, 13, 14
      error handling and, 278, 279
      factoring out, 187
      fixed-width data, 154-157
      globbing, 167
      grepping, 169, 170
      hash values, 166
      homonyms and, 177, 178
      mapping, 169, 170
      parentheses and, 13, 176
      reversing lists, 152, 153
      reversing scalars, 153, 154
      separated data, 157, 158
built-in functions (continued)
      sleeping, 168, 169
      sorting, 149-152
      string evaluations, 161-164
      substrings, 165, 166
      utilities, 170-174
      variable-width data, 158-161

C[ Top ]
C language, 442
Cache::Mmap module, 319
caching
      best practice, 481
      for optimization, 463, 464
      preserving between sorts, 151
      recommendations, 460-462
      SHA values, 150
      subroutine, 462, 463
caller function, 191
capitalization
      best practice, 473
      heredocs and, 63
      naming conventions, 45, 46
capture variables, 253-257, 478
carp( ) subroutine, 13, 490
Carp module, 13, 283, 284, 471, 487
caught( ) method, 287, 290, 298
Changes file, 416
character strings (see text strings)
characters, named, 247, 248
charnames module, 487
chroot function, 106
chunking
      best practices, 469, 472
      code layout and, 23, 24
      data, 320
circular linked lists, 232
class hierarchies
      attribute building, 387, 388
      attribute demolition, 384-386
      autoloading, 393-396
      automating, 383, 384
      base class initialization, 371-376
      best practice, 480
      blessing objects, 365-367
      coercions, 388
      construction/destruction, 376-383
      constructor arguments, 367-370
      cumulative methods, 389-393
      inheritance and, 360
      objects and, 361-365
class methods, 142, 334
Class:: namespace, 318
Class::Classless module, 319
Class::Data::Inheritable class, 319
classes
      algebraic, 354-356
      best practice, 479
      capitalization of, 45
      character, 248
      destructors and, 336-338
      encapsulation and, 324, 471
      exception, 287, 293-296, 479
      grammar rules, 39
      inheritance and, 381
      inside-out objects and, 332
      interfaces and, 351-354
      lvalue accessors and, 348
      naming conventions, 37
      object orientation and, 320
      overloading operators and, 355
      protected access, 359
      unique attributes and, 373
      (see also base classes)
Class::Std module (CPAN)
      attribute building, 387
      attribute demolition, 384-386
      autoloading, 393-396
      automating class hierarchies, 383
      best practice, 471
      coercions, 388
      cumulative methods, 389-393
      description, 488
Class::Std::Utils module (CPAN), 330, 374, 488
Class::Tables module, 319
cloning, 334-336, 479
"close" as ambiguous name, 48
close statement, 208, 209
cmp_these( ) subroutine, 490
code layout
      assignments, 30, 31
      automated, 33-35
      best practices, 469, 472, 473
      blocks, 22
      bracketing, 9-11
      breaking by precedence, 29, 30
      breaking long lines, 27-29
      built-in functions, 13, 14
      chunking, 23, 24
      commas, 17, 18
      else statement, 24-25
      indentation, 19-20
      keys and indices, 14
      keywords, 11, 12
      left edge of, 27
      line lengths, 18, 19
      lists, 32, 33
      non-terminal expressions, 29
      operators, 14
      semicolons, 15, 17
      subroutines and variables, 12
      tabs, 20, 22
      ternaries, 31, 32
      vertical alignment, 26-27
code-ref values, 192
coding (see programming)
coercions
      best practice, 480
      class hierarchies and, 388
      overview, 356-358
colon (:), 31
command-line processing
      best practice, 479
      conventions for, 301-303
      enforcing consistent structure, 300, 301
      in-situ arguments, 304-305
      interapplication consistency, 314-317
      interface consistency, 311-314
      meta-options, 303, 304
      Perl debugger and, 437
      standardizing, 306-310
commas (,)
      best practice, 472
      code layout and, 17, 18
      fat, 55, 66-68, 474
      in lists, 17, 32
      precedence of, 71
      thin, 68, 69, 474
      version numbers and, 406
Comma-Separated Values (CSV), 158-161
comments
      # character and, 236
      automating progress indicators, 224
      best practice, 475
      documenting algorithms, 142, 143
      empty strings and, 53
      end-of-line, 143, 144
      escaped characters and, 55
      forward slashes and, 245
      identifiers and, 40
      maintainability and, 23
      overview, 141, 142
      personal stumbling blocks, 144, 145
      readability of, 451
      shift function and, 180
      smart, 439, 440
      use English pragma and, 80
COMMON USAGE MISTAKES template, 138
compilation
      semicolons and, 16
      warning-free, 432, 433
Comprehensive Perl Archive Network (see CPAN)
conditional tests
      aligning, 31
      complex mappings and, 113
      distributed control and, 126
      negative control statements and, 97-99
      nesting, 96
      Perl and, 97
      postfix selectors and, 94
Config::General module (CPAN), 447, 488
Config::Std module (CPAN), 447, 448, 488
Config::Tiny module (CPAN), 447, 488
CONFIGURATION AND ENVIRONMENT template, 135, 137
configuration files
      best practices, 469, 481
      modules and, 416
      recommendations, 445-448
constants
      best practices, 471, 473
      capitalization of, 45
      fat commas and, 66
      indices as, 14
      values and expressions, 55-58
      (see also Readonly module)
constructors
      best practice, 479, 480
      class hierarchies and, 360, 376-383
      Class::Std module and, 389
      cloning objects, 334-336
      indirect objects and, 349
      as object methods, 367
      overview, 333
      passing arguments, 367-370
Contextual::Return module (CPAN), 191-194, 488
"contract" as ambiguous name, 48
control structures
      best practice, 474, 475
      chained negatives, 99
      complex mappings, 113-114
      C-style loops, 100, 101
      distributed control, 126-128
      do-while loops, 123-125
control structures (continued)
      for vs map, 110-114
      if blocks, 93, 94
      iterator variables, 105-107
      keywords and, 11
      linear coding, 125-126
      list generation, 110, 111
      list processing side-effects, 114-117
      list selection, 111-112
      list transformation, 112, 113
      loop labels, 129-131
      multipart selections, 117
      necessary subscripting, 103-105
      negative statements, 97-98
      non-lexical loop iterators, 108-110
      postfix modifiers, 96-97
      postfix selectors, 94, 95
      redoing, 128, 129
      tabular ternaries, 121-123
      unnecessary subscripting, 101-103
      value switches, 118-121
corner-cases, 426
$COUNTRY_LEN keyword, 165
CPAN (Comprehensive Perl Archive Network)
      best practice, 480
      integrating other languages and, 442
      modules and, 397, 418, 419
      recommended modules, 488-490
CPAN module, 487
croak( ) subroutine
      description, 490
      OO exceptions, 287, 289
      parentheses and, 13
      postfix selectors, 94
      reporting failure, 283, 284, 285
      throwing exceptions, 181
crypt function, 150, 461
cryptographic hash functions, 150
C-style, 100, 101, 474
CSV (Comma-Separated Values), 158-161
:CUMULATIVE marker, 392, 393
:CUMULATIVE method, 389-393
cumulative methods, 389-393, 480
=cut directive, 141
cyclic references, 232-234, 477

D[ Top ]
dash (-), 302, 303
data
      best practice, 476
      chunking, 320
      fixed-width, 154-157
      separated, 157, 158
      variable-width, 157, 158-161
_ _DATA_ _ marker, 141
Data::Alias module (CPAN), 104, 471, 488
Data::Dumper module, 333, 438, 487
DateTime module (CPAN), 418, 488
DBI module (CPAN), 418, 488
debugging
      best practices, 469, 481
      defined, 273
      error handling and, 275
      exception messages and, 285
      manual, 437-439
      match variables and, 83
      open statement, 204
      overview, 427-429
      Perl debugger, 436, 437, 481
      profiling and, 465
      revision control and, 442
      semi-automatic, 439, 440
      strictures and, 433-436
      use warnings pragma, 431, 432
      warning-free compilation and, 432
      whitespace and, 250
      (see also testing)
decimal numbers, 59
deferencing, with arrows, 227, 228
definedness tests, 184
delete function, 102
delimiters
      best practice, 473, 478
      brace, 242-246
      recommended, 246
      text strings and, 51-53
      warnings and, 431
DEMOLISH( ) method
      attribute demolition, 386
      construction/destruction and, 381, 384, 385
      cumulative methods and, 389
DEPENDENCIES template, 135
dereferencing, 42, 228-229, 477
DESCRIPTION template, 134
DESTROY( ) method, 337, 378, 381, 394
destructors
      best practice, 479, 480
      class hierarchies and, 376-383
      Class::Std module and, 389
      overview, 336-338
Devel::DProf module, 465-466, 487
Devel::Size module (CPAN), 488
Devel::SmallProf module (CPAN), 466
Device::SerialPort module (CPAN), 418
DIAGNOSTICS template, 134, 137
die statement, 94, 283, 284, 287
Digest module, 150
digests, 150, 151
(DISCLAIMER OF) WARRANTY template, 139
do statement, 213, 214, 331
documentation
      algorithmic, 142, 143
      best practice, 475, 478
      boilerplates, 133-137
      comments, 141, 142
      consistency in, 311-314
      contiguity, 140
      cryptographic hash functions, 150
      defensive, 144, 145
      discursive, 145-147
      elucidating, 143, 144
      error handling, 286, 287
      extended boilerplates, 138, 139
      indicative, 145
      location of, 139
      Perl debugger, 437
      perlmodlib, 418
      perltie, 451
      position of, 140
      proofreading, 148
      technical, 133, 141
      types of, 132, 133
      user, 133, 140, 147
dollar sign ($), 89, 195
dollar-underscore ($_)
      @_ array and, 178
      apply function and, 173
      best practice, 474
      modifying, 114-117
      overview, 85-87
      postfix looping and, 96
      prevalence of, 74
      readability of, 105, 107
dot (.) operator, 355
dot metacharacter, 240
double quotation (")
      empty strings and, 53
      escaped characters, 54
      heredocs and, 64
      single-character strings and, 54
      string delimiters and, 51, 52
do-while loops, 123-125, 475
dprofpp application, 465, 466

E[ Top ]
each function, 105
edge cases, 3, 426
efficiency, 4, 454
else statement, 24-25, 122
elsif statement, 25, 117
Emacs editor
      converting tabs to spaces, 22
      manual debugging and, 439
      matching brackets, 10
      overview, 483-484
      setting margins, 18
empty strings, 53, 426, 473
enbugging, 466, 467, 481
encapsulation
      best practice, 479, 481
      class hierarchies and, 361-365
      cleverness and, 454-456
      inside-out objects and, 324, 337, 353
      lvalue methods and, 347
      objects and, 321, 323-333
      protected access and, 359
=end directive, 145, 147
_ _END_ _ marker, 141, 238, 241
end-weight problem, 27
English module, 487
%ENV variable, 430
@ENV variable, 430
eq comparison, 271-272
equals sign (=), 302
error handling
      best practice, 478, 479
      built-in failures, 278, 279
      contextual failure, 279, 280
      defined, 273
      documentation, 286, 287
      do-while loops and, 124
      error messages and, 284-285, 290
      exception classes, 293-296
      exception hierarchies, 291-292
      exceptions, 274-278, 292
      Getopt::Clade module and, 310
      I/O operations and, 208, 209
      methods and, 338
      OO exceptions, 287-290
      pseudohashes and, 322
      recoverable failure, 281-282
      reporting failure, 283-284
      systemic failure, 280, 281
      unpacking exceptions, 296-298
error messages
      best practice, 478
      documenting, 286, 287
      error handling and, 284-285
      Getopt::Clade module and, 310
      testing and, 424
      volatile, 290
eval function
      benchmarking and, 457
      best practice, 476
      error handling, 274, 277, 278
      overview, 161-164
      recoverable failure and, 282
$EVAL_ERROR variable, 289, 292, 297, 298
EXAMPLES template, 138
exception classes
      best practice, 479
      building, 293-296
      caught( ) method, 287
exception handling
      barewords and, 66
      best practices, 469, 471, 478, 479
      caught( ) method, 287, 290, 298
      croak( ) subroutine, 181
      exception classes, 293-296
      exception hierarchies, 291-292
      failed builtins, 278, 279
      named arguments, 183
      OO exceptions, 287-290
      overview, 274-278
      processing exceptions, 292
      recommendations, 276
      recoverable failure, 281, 282
      reporting failure, 283-284
      unpacking exceptions, 296-298
      version requirements and, 405
Exception::Class module (CPAN)
      best practices, 471, 488
      exception classes, 295, 296
      unpacking exceptions, 298
exec function, 274
existence tests, 184
Exporter module, 409-410
exporting
      best practice, 480
      declarative, 409-410
      modules, 407-408
expressions
      barewords, 65, 66
      best practice, 472, 473, 474
      breaking before operators, 27-29
      breaking by precedence, 29, 30
      constants and, 55-58
      empty strings, 53
      escaped characters, 54, 55
      exit points, 126
      fat commas, 66-68
      grep function, 169
      here documents and, 61
      heredoc indentation, 61-62
      heredoc quoters, 64, 65
      heredoc terminators, 62-64
      implicit returns and, 197
      leading zeros, 58, 59
      list membership, 71, 72
      lists and, 71
      long numbers, 59, 60
      low-precedence operators, 70-71
      map function, 169
      match variables and, 82
      multiline strings, 60
      naming conventions, 40
      non-terminal, 29
      precedence operators in, 70
      readability of, 14
      single-character strings, 53, 54
      string delimiters, 51-53
      thin commas, 68, 69
      (see also regular expressions)
extended formatting, 236, 237
extract_initializers_from( ) method, 374, 375
ExtUtils::MakeMaker module, 404

F[ Top ]
factoring
      default argument values, 186
      out built-in functions, 187
      slices, 90-92
fail( ) subroutine, 407, 408, 410
fat commas (=>)
      best practice, 474
      Readonly subroutine, 55
      values and expressions, 66-68
Fatal module
      built-in failures, 278, 279
      contextual failure, 280
      description, 471, 487
Fibonacci numbers, 49
$FIELD_COUNT argument, 158
File::Glob module, 487
filehandles
      anonymous, 204
      *ARGV, 216, 219
      autoflushing, 224, 225
      barewords as, 65
      best practices, 470, 476
      closing explicitly, 209, 210
      formats and, 449
      indirect, 204, 205
      I/O and, 202-204
      localizing, 205-206
      openhandle function and, 171
      opening cleanly, 207, 208
      printing to, 217
      seek function and, 156
      select function and, 224
      slurping, 213, 214
      tied, 451-453
File::Hierarchy class, 332, 337
$FILE_PATTERN keyword, 167
files
      error checking, 208, 209
      memory and, 213
      plain-text, 141
File::Slurp module (CPAN), 488
File::Temp module, 487
filtering
      encapsulated cleverness and, 455
      grep function and, 456
      list values, 187
      lists, 169
Filter::Macro module (CPAN), 488
first( ) subroutine
      aliases and, 115
      complex mappings, 113
      description, 172, 490
      dollar-underscore and, 114, 115, 116
      grep function and, 110
      list selections and, 112
      parentheses and, 13
first_index( ) subroutine, 173, 490
fixed-width data, 154-157
flags
      best practices, 469, 477
      command-line conventions, 301, 302
      distributed control and, 128
      error handling via, 274
      failed builtins and, 278
      lazy, 242
      meta-options and, 303, 304
      tests and, 124
floating-point numbers, 60, 404
flock function, 274
flow of control
      error handling and, 276, 280
      loop labels and, 129-131
      postfix selectors and, 94
flyweight scalars, 324
=for directive, 145
for statement
      C-style and, 100, 101
      input loops and, 211-212
      list generation and, 110, 111
      list selections and, 111-112
      list transformations, 112, 113
      vs map, 110-114
      non-lexical loop iterators and, 108-110
      postfix looping and, 96-97
      recoverable failure and, 282
      reversing lists and, 153
      Smart::Comments module and, 224
      while statement and, 128, 129
fork statement, 281
form( ) subroutine, 450, 490
format statement, 449-451
formatting
      best practice, 481
      extended, 236, 237
      recommendations, 449-451
forward slash (/), 243
FREQUENTLY ASKED QUESTIONS template, 138
functions
      automating sorts, 164, 165
      caching and, 461
      code layout and, 13, 14
      error handling and, 280
      fixed-width data, 154-157
      globbing, 167
      grepping, 169, 170
      hash, 150, 166
      mapping, 169, 170
      reversing lists, 152, 153
      reversing scalars, 153, 154
      separated data, 157, 158
      sleeping, 168, 169
      sorting, 149-152
      string evaluations, 161-164
      substrings, 165, 166
      utilities, 170-174
      variable-width data, 158-161
      (see also built-in functions)

G[ Top ]
\G metacharacter, 257
garbage collection
      hashes, 234, 332, 337
      inside-out objects and, 337
/gc flag, 257-259, 307
gensym( ) subroutine, 204
Getopt::Clade module (CPAN)
      command-line processing, 310
      description, 488
      interapplication consistency, 314
      interface consistency, 311, 314
Getopt::Euclid module (CPAN), 311, 314, 315, 489
Getopt::Long module (CPAN), 308, 309, 314, 487
Getopt::Std module (CPAN), 308
getpwent function, 191
glob function, 167, 168, 476
global variables, 82, 297, 449
gmtime function, 191
GNU bracketing, 10, 11
goto statement, 94
grammar rules, identifiers and, 37, 38, 39
grep function
      aliases and, 115
      arrays and, 43
      benchmarking and, 455, 458, 459
      best practice, 476
      complex mappings, 113
      contextual return values, 189
      dollar-underscore and, 87, 114, 115, 116
      first function and, 110
      homogeneous list-returning subroutine, 190
      keys in, 103
      looping and, 112
      overview, 169, 170
      scalar return values, 187
      semicolons and, 17
      spacing statements, 22
Guttman-Rosler Transform, 164

H[ Top ]
hash algorithms, one-way, 150
hash functions, cryptographic, 150
hashes
      anonymous, 324, 330, 331, 454
      base class initialization and, 371-376
      best practices, 470, 473, 476, 479
      built-in functions and, 166
      constructor arguments and, 367-370
      empty, 374
      fat commas and, 66
      grammar rules, 39
      inside-out objects and, 324, 330
      iterating, 104
      keys and indices, 14
      as look-up tables, 118
      multi-contextual return values and, 192
      named arguments and, 182, 183
      naming conventions, 43
      pseudohashes, 322, 479
      reclaiming, 337
      references to, 233, 234
      restricted, 322, 323
      slicing, 89, 90, 102, 193, 455
      sort function and, 151
      unnecessary subscripting, 101-103
      vertical alignment and, 27
hash-ref values, 192
Hash::Util module, 322, 323
--help option, 303, 306, 310, 311
here documents (heredoc)
      best practice, 473
      indentation in, 61-62
      quotes in, 64, 65
      terminators in, 62-64
      values and expressions, 61
heterogeneous list-returning subroutine, 191
hierarchies, 320, 322
      (see also class hierarchies)
homogeneous list-returning subroutine, 190
homonyms
      ambiguous names and, 48
      best practice, 476
      methods and, 338
      in subroutines, 177, 178
HTML::Mason module (CPAN), 418, 489
hyphen (-), 44, 302, 303

I[ Top ]
ident( ) subroutine, 330, 490
identifiers
      abbreviating, 46
      best practices, 470, 473
      capitalization of, 45, 46
      keys and, 66
      naming conventions, 37-40
      spaces and hyphens in, 44
      unrecognized, 65
if keyword
      best practice, 474
      cascaded equality tests, 118-121
      cascading statements, 117
      flow-of-control statements and, 94, 95
      postfix form, 93, 94
      readability, 97-98
import( ) subroutine, 444
$INC variable, 430
%INC variable, 430
@INC variable, 430
INCOMPATIBILITIES template, 135
indentation
      best practice, 472, 473
      breaking by precedence and, 30
      breaking expressions and, 27, 28
      heredoc, 61-62
      justification and, 61
      K&R bracketing, 9
      recommended depth, 19-20, 21
indicators, progress, 222-224
indices
      array, 88-89, 101, 102, 474
      best practice, 472
      code layout and, 14
      iterating, 103
      negative, 88-89
      vertical alignment, 27
indirect filehandles, 204, 205
indirect objects, 349-351, 479
inheritance
      best practice, 480
      class hierarchies and, 360
      construction/destruction and, 376-383
      new( ) method and, 376
      object orientation and, 321
      positional arguments and, 368
      pseudohashes and, 322
INI file format, 445, 447
initialization
      of attributes, 387, 388
      base classes, 371-376
      best practice, 480
      variables and, 78-79
Inline:: module (CPAN), 442-445, 489
inodes, 305
input operator, 204
input record separator, 213, 214, 215
$INPUT_RECORD_SEPARATOR variable, 213
inside-out objects
      base class initialization and, 371
      class hierarchies and, 361-365
      Class::Std module and, 384
      destructors and, 336-338
      encapsulation and, 324, 337, 353
install_sub( ) method, 164
instance methods, 142, 334
int function, 461
integers
      do-while loops and, 124
      exception handling, 291
      leading zeros and, 59
      object references and, 330
      sleep function and, 168
interactive( ) subroutine, 220, 491
interactive applications, 217, 218, 222-223
interfaces
      autoloading and, 394
      best practices, 469, 470, 479, 480
      class, 351-354
      consistency in, 301, 311-314
      CPAN tools, 442
      defining, 306
      documenting, 311
      Getopt::Clade module and, 310
      inside-out objects and, 332
      modules and, 397-401, 407
      object orientation and, 321
      variables and, 409, 411-414
Intuitive Programmer Syndrome, 1, 2
inverted indices, 324
I/O (input/output)
      autoflushing, 224-226
      best practice, 476
      clean-up, 209, 210
      error checking, 208, 209
      filehandles, 202-204, 217
      indirect filehandles, 204, 205
      input loops, 211-212
      interactivity, 218-220
      line-based input, 212, 213
      localizing filehandles, 205-206
      opening cleanly, 207, 208
      power slurping, 214-215
      progress indicators, 222-224
      prompting, 217, 220-221
      slurping, 213, 214
      standard input, 216
IO::File module, 207, 208, 487
IO::Handle module, 208, 217, 226, 487
IO::InSitu module (CPAN), 305, 489
IO::Interactive module (CPAN), 219, 489
IO::Prompt module (CPAN)
      best practices, 471
      description, 489
      exporting and, 408
      interfaces and, 398, 399, 400
      power prompting, 220-221
is( ) subroutine, 423, 491
@ISA package variable, 360
is_interactive( ) subroutine, 218-220, 491
isomorphic operators, 354-356
is_weak( ) subroutine, 171, 491
iterative list-returning subroutine, 191
iterator variables
      best practice, 474
      loop, 108-110
      overview, 105-107
      postfix loops and, 96

J[ Top ]
justification, 61, 63

K[ Top ]
keys
      best practice, 472
      code layout and, 14
      constructing regular expressions, 261
      extracting, 259, 260
      fat comma and, 66
      grep and, 103
      hash slices and, 90
      identifiers as, 66
      iterating, 103, 104
      locking, 322
      slice factoring, 90, 92
      testing considerations, 427
      vertical alignment, 27
key/value pairs, 66, 91
keywords
      best practice, 472
      built-in functions as, 13
      code layout and, 11, 12
      contextual return values and, 193
      cuddling and, 24
      subroutines and, 178
K&R bracketing
      code layout, 9, 10, 11
      cuddling and, 24
      multiline lists and, 33

L[ Top ]
languages, 442-445, 481
"last" as ambiguous name, 48
last statement
      best practices, 470
      flow of control and, 94
      loop labels and, 129
      recoverable failure and, 282
last_index function, 173
"left" as ambiguous name, 48
lexical variables
      @_ and, 181
      best practices, 75, 470, 474
      constants and, 55
      declaration scope and, 331
      eval function and, 457
      filehandles and, 204, 205, 209, 210, 226
      loops and, 105-107
      my keyword, 108-110
      overview, 73-74
      restricting, 328
Lexical::Alias module (CPAN), 471, 489
lib/ subdirectory, 416
LICENCE AND COPYRIGHT template, 136
line boundaries, 237-239
lines
      best practice, 472
      breaking, 27-29
      comments and, 143
      empty, 146
      lists breaking across, 32
      multiple statements on, 22
      recommended length, 18, 19
      strings over multiple, 60
link function, 178
Linnaean system, 37
@list argument, 172, 173
List::Cycle module (CPAN), 489
List::MoreUtils module (CPAN)
      any function, 71
      best practices, 471
      description, 489
      functions, 172-174
      utilities, 170
lists
      best practice, 473, 474, 475
      circular linked, 232
      code layout, 32, 33
      commas in, 17, 32, 69, 71
      concatenating, 172
      contextual return values, 188-191
      filtering, 169
      generating, 110, 111
      processing side-effects, 114-117
      readability of, 26
      reversing, 152, 153
      scalar return values and, 188
      selecting, 111-112
      slice factoring, 90
      testing membership, 71, 72
      transforming, 112, 113, 169
      values and expressions, 71
List::Util module (CPAN)
      best practices, 471
      description, 487
      functions, 172, 174
      interfaces and, 400
      utilities, 170
local declaration, 77, 78, 81
localization
      best practice, 474
      filehandles and, 205-206
      package variables, 77, 78
      punctuation variables, 81, 82
localtime function, 188, 189, 191
lock_hash( ) subroutine, 322
lock_keys( ) subroutine, 322
lock_value( ) subroutine, 322
Log::Stdlog module (CPAN), 489
long numbers, 59, 60
looks_like_number( ) subroutine, 171, 491
loop iterator variables, 108-110
loops
      abbreviations in, 47
      automatic progress indicators for, 224
      best practices, 470, 474, 475, 477
      configuration files and, 447
      contorted, 127
      do-while, 123-125
      error handling and, 275, 277
      eval function and, 161
      for statements and, 100, 101
      grep function and, 112
      incrementing and, 128
      input, 211-212
      labeling, 129-131, 470, 475
      lvalues and, 166
      map function and, 111
      named lexicals and, 105-107
      postfix modifiers and, 96
      recoverable failure and, 282
      reversing lists and, 153
      subscripting in, 103-105
      tied variables and, 452
      unnecessary subscripting, 101-103
      unpack function and, 157
lvalue accessors, 346-349
lvalue substring, 165, 166

M[ Top ]
/m flag, 237-239, 470
magic goto, 435
maintainability
      class hierarchies and, 359
      classes and, 352
      cleverness and, 453, 454
      of coding style, 4, 5
      comments and, 23
      constructors and, 336
      Contextual::Return module and, 193
      C-style loops and, 100
      design and, 398
      documentation and, 132
      iterator variables and, 107
      loop labels and, 130
      named arguments and, 183
      overloading operators and, 354
      slice factoring and, 91
      substr function and, 165
      volatile error messages and, 290
Makefile.PL, 416
make_sorter( ) subroutine
      automating sorts, 165
      description, 491
      string evaluations, 162, 163, 164
--man option, 303, 310, 311
MANIFEST file, 416
map function
      aliases and, 115
      arrays and, 43
      best practice, 476
      complex mappings and, 113, 114
      dollar-underscore and, 87, 114, 116
      vs for, 110-114
      homogeneous list-returning subroutine, 190
      list generation and, 110, 111
      list transformation, 112, 113
      overview, 169, 170
      Schwartzian Transform and, 152
      semicolons and, 17
      spacing statements, 22
MATCH( ) subroutine, 84
$MATCH variable, 82, 83
match variables, 82-84, 474
max( ) subroutine, 13, 172, 491
maxstr( ) subroutine, 172, 174, 491
memoization, 152, 462, 463, 481
memoize( ) subroutine, 462, 463, 491
Memoize module (CPAN), 152, 462, 463, 487
memory
      best practice, 481
      inside-out objects and, 332, 337
      map function and, 113
      recommendations, 459, 460
      slurping and, 212
metacharacters, 247, 478
meta-options, 303, 304
method calls, 292, 321, 349, 452
methods
      accessing attributes, 340-346
      best practice, 479
      capitalization of, 45
      cloning and, 334
      convenience, 354
      cumulative, 389-393, 480
      grammar rules, 40
      lvalue, 347
      overview, 338-340
      sub keyword, 142
min( ) subroutine, 172, 491
minstr( ) subroutine, 172, 491
minus sign (-), 88
missing arguments, 184-185
Module::Build module (CPAN), 404, 489
modules
      best practices, 469, 480
      core, 487, 488
      CPAN and, 397, 418, 419
      creating, 415-417
      declarative exporting, 409-410
      exporting, 407-408
      interface variables, 411-414
      interfaces and, 397-401, 407
      refactoring, 397, 401-404
      standard library, 417, 418
      testing considerations, 427
      version numbers, 404, 405
      version requirements, 405-407
Module::Starter module (CPAN), 416, 489
Module::Starter::PBP module (CPAN), 416, 417, 489
mutators, 341, 351
my keyword, 108-110

N[ Top ]
NAME template, 134, 136
named arguments, 182-183, 470, 476
named characters, 247, 248
named escapes, 54
nameless scalars, 331
names
      ambiguous, 48
      arguments and, 182-183
      best practice, 473
      capture variables and, 254
      constants and, 56
      for methods, 339
      lexical variables, 331
name/value pairs, 66, 182
naming conventions
      abbreviations, 46-47
      advantages of, 36
      ambiguous names, 48
      arrays and hashes, 43
      best practice, 473
      boolean values, 40-41
      capitalization, 45, 46
      filenames, 304-305
      identifiers, 37-40
      methods and, 338
      reference variables, 41, 42
      underscores, 44
      utility subroutines, 49
negative indices, 88-89
nesting
      abbreviations in loops, 47
      conditional tests, 96
      loops and, 131
new( ) method
      attribute building and, 388
      construction/destruction and, 379
      constructors and, 333-336
      indirect objects and, 350
      inheritance and, 376
      UNIVERSAL class and, 381
newline character, 60, 236
NEXT module, 389
next statement, 94, 129, 470
"no" as ambiguous name, 48
none( ) subroutine, 173, 491
not operator, 70
notall( ) subroutine, 173, 491
nouns, naming conventions, 38
numbers
      best practice, 473
      conversion subroutines for, 388
      long, 59, 60
:NUMERIFY method, 388

O[ Top ]
Object:: namespace, 318
object orientation
      appropriate criteria, 320-321
      best practice, 479
      as choice, 319
      error handling, 287-290
objects
      accessors, 340-346
      best practice, 479, 480
      blessing, 365-367
      building, 318
      class hierarchies and, 361-365
      class interfaces, 351-354
      cloning, 334-336
      coercions, 356-358
      constructors, 333
      destructors, 336-338
      encapsulation and, 321, 323-333
      indirect, 349-351, 479
      lvalue accessors, 346-349
      methods, 338-340
      object orientation as choice, 319
      operator overloading, 354-356
      pseudohashes and, 322
      restricted hashes, 322
      (see also inside-out objects)
Occam's Razor, 351
oct function, 59
octal numbers, 59
ok( ) subroutine
      declarative exporting and, 410
      description, 491
      modular testing and, 422
      testing and, 407
one-way hash algorithms, 150
only module (CPAN), 406, 407, 489
open statement
      debugging, 204
      error checking and, 208, 209
      error handling, 274
      opening cleanly, 207, 208
      recoverable failure and, 281
      scalar variables and, 204
openhandle( ) subroutine, 171, 491
operators
      best practice, 472, 474, 480
      breaking by precedence, 29, 30
      breaking expressions before, 27-29
      code layout and, 14
      comma and, 69, 71
      isomorphic, 354-356
      low-precedence, 70-71
      object orientation and, 321
      overloading, 354-356
      sub keyword and, 142
      ternary, 31, 32, 121-123
      types of, 51
      vertical alignment of, 26, 27
OPTIONS section (documentation), 311
OPTIONS template, 137
or operator, 70, 185
Orcish Man?uvre, 150, 164
overload module, 487

P[ Top ]
(?p) marker, 84
package filehandles
      autoflushing, 226
      braces and, 217
      clean-up, 209
      localizing, 205, 206
      naming considerations, 203, 204
package variables
      benchmarking and, 457
      best practices, 470, 474
      converting to, 306
      declarative exporting and, 409
      formats and, 449
      interfaces and, 414
      localization, 77, 78
      overview, 75-77
      self-declaring, 73
      strictures and, 430
packages
      capitalization of, 45
      grammar rules, 39
      naming conventions, 37
pairwise( ) subroutine, 173, 491
paragraphs
      chunking and, 23, 24
      defined, 23
      documenting, 142
parameters
      best practices, 470
      methods and, 338
      named arguments and, 182-183
      numbered, 179
      testing, 426
parentheses ( )
      backtracking and, 269, 270
      best practices, 470, 478
      bracketing, 9, 10
      built-in functions and, 13
      capturing, 252
      control structure keywords, 11
      factoring alternations, 267
      long lists and, 32, 33
      match variables and, 83
      precedence operators and, 70
      subroutines and, 12, 175-177
      variables, 12
      warnings and, 431
Parse::RecDescent module (CPAN), 418, 489
pass( ) subroutine, 407, 410
:PASS tagset, 410
passing by reference, 196
pattern matching
      backtracking and, 269-271
      captured values and, 253-257
      factoring alternations, 266-268
      match variables and, 82, 83
      piecewise, 257-259
      regular expressions, 240-241
      string comparisons, 271, 272
perldebtut documentation, 437
perldebug documentation, 437
Perl debugger, 436, 437, 481
Perl standard library, 417, 418, 480
Perl6::Builtins module (CPAN), 281, 489
Perl6::Export::Attrs module (CPAN), 410, 489
Perl6::Form module (CPAN), 450, 489
Perl6::Rules module, 408
Perl6::Slurp module (CPAN), 214-215, 408, 489
perldiag documentation, 287
perldoc utility, 132, 139
perlfunc manual, 165, 274
perlmodlib documentation, 418
perltidy code formatter, 34, 35, 469
perltie documentation, 451
perlunicode documentation, 249
perlxstut documentation, 442
Plain Old Documentation (see documentation)
plain-text files, 141
plug-ins, 416
plus (+) operator, 356
plus sign (+), 15
=pod directive, 141
.pod files, 141
POD (see documentation)
POE module (CPAN), 418, 489
pop function, 349
POSIX module, 281
postfix form
      best practice, 474
      flow-of-control statements, 94, 95
      statement modifiers, 96-97
POSTMATCH( ) subroutine, 84
$POSTMATCH variable, 82, 83
precedence
      best practice, 472
      breaking expressions by, 29, 30
      parentheses and, 13
      spaces and, 15
prefixes
      ampersand in, 176
      command-line conventions, 302
      heredoc terminators and, 62
      naming conventions, 46
      utility subroutines and, 49
PREMATCH( ) subroutine, 84
$PREMATCH variable, 82, 83
prepositions
      hashes and, 43
      naming conventions, 39, 40
print statement
      barewords and, 65
      debugging and, 437
      error checking and, 208, 209
      error handling, 274
      human nature and, 276
      select function and, 224, 225
printing to filehandles, 217
process verbs, 67
processing, command-line (see command-line processing)
profiling, 464-466, 481
programming
      breaking habits, 7
      cleverness and, 453, 454
      developing style, 2
      encapsulated cleverness, 454-456
      framework in, 2
      Intuitive Programmer Syndrome, 1, 2
      linear coding, 125-126
      revision control, 441, 442
progress indicators, 222-224
prompt( ) subroutine
      as builtin, 13
      description, 491
      interfaces and, 399, 400
      power prompting and, 220, 221
prompting
      best practice, 477
      power, 220-221
      simple, 217
proofreading, 148, 475
properties
      best practice, 478
      naming conventions, 40
      regular expressions and, 248, 249
prototypes, 194-196, 476
prove utility, 424, 425
pseudohashes, 322, 479
punctuation variables
      autoflushing, 225
      best practices, 471, 474
      listed, 73
      localization, 81, 82
      overview, 79-81
      regex and, 82
push( ) method, 110, 111, 339

Q[ Top ]
q{} string, 262
qq{} string, 262
qr{} string, 262
question mark (?), 31, 32, 262
quicksort algorithm, 149
quotes in heredocs, 64, 65, 473
qv( ) subroutine, 404, 405, 406, 491

R[ Top ]
rand function, 461
%RE hash, 263
readability
      abbreviations and, 47
      assignments and, 31
      built-in functions and, 13
      cleverness and, 454
      comments and, 451
      complex mappings, 114
      cuddling and, 24
      debugging and, 439
      of expressions, 14
      fat commas and, 66
      of lists, 26
      look-up tables and, 120
      multiline strings and, 60
      named constants and, 56
      negative control statements, 97-99
      optimizing for, 4
      semicolons and, 16
      slice layout, 90
      statements on lines, 22
      string delimiters and, 52
      tabular ternaries and, 122
      underscores and, 59, 60
      use English pragma, 79, 80
      variables and, 105
readdir function, 191
read_file( ) subroutine, 491
readline function
      caching and, 461
      configuration files and, 447
      contextual return values, 189
      globbing and, 167
      iterative subroutines and, 191
      module interfaces and, 399
      scalar variables, 167
      simple slurping, 213
      slurp( ) subroutine and, 215
README file, 416
readonly( ) subroutine, 171, 491
Readonly module (CPAN), 55, 58, 471, 489
readpipe function, 189
"record" as ambiguous name, 48
$RECORD_SEPARATOR argument, 158
redo statement
      best practices, 470
      flow of control and, 94
      loop labels and, 128, 129
      while statement and, 128, 129
reduce( ) subroutine, 172, 491
_ref suffix, 41, 42
refactoring
      best practice, 480
      considerations, 466, 467
      modules and, 397, 401-404
refaddr( ) subroutine, 171, 330, 491
reference variables, 41, 42, 473
references
      best practice, 477
      braced, 228-229
      cyclic, 232-234
      dereferencing, 227, 228
      symbolic, 230-231
reftype( ) subroutine, 171, 491
regex (see regular expressions)
Regexp::Assemble module (CPAN), 262, 489
Regexp::Autoflags module (CPAN), 242, 489
Regexp::Common module (CPAN), 263-265, 471, 490
Regexp::MatchContext module (CPAN), 84, 490
regular expressions
      alternations, 265, 266
      backtracking, 269-271
      best practice, 471, 477
      brace delimiters, 242-246
      canned, 263-265
      capture variables, 253-257
      capturing parentheses, 252
      command-line processing and, 307
      configuration files and, 447
      constructing, 261-262
      delimiters, 246
      end of string, 240
      exception hierarchies and, 291
      extended formatting, 236, 237
      factoring alternations, 266-268
      fixed-width data and, 155
      input record separator and, 215
      lazy flags, 242
      line boundaries, 237-239
      match variables, 82-84
      metacharacters, 247
      named characters, 247, 248
      OO exceptions and, 288
      (?p) marker, 84
      pattern matching, 240-241
      piecewise matching, 257-259
      properties, 248, 249
      string boundaries, 239
      string comparisons, 271, 272
      tables and, 259-261
      unconstrained repetitions, 250-252
      whitespace, 249, 250
remonstrate tool, 300
repetitions, unconstrained, 250-252
reporting failures, 3, 283-284, 478
require function, 106
REQUIRED ARGUMENTS section (documentation), 311
REQUIRED ARGUMENTS template, 136
restricted hashes, 322, 323
return scalar statement, 186-188
return statement
      do-while loops and, 125
      flow of control and, 94
      implicit, 197-199
      returning failure, 199, 201
      scalar return values, 186-188
return undef statement, 200
return values
      best practices, 470, 476
      contextual, 188-191
      cumulative methods and, 391
      error handling and, 274, 276
      failed exceptions and, 278
      methods and, 338
      multi-contextual, 191-194
      scalar variables and, 186-188
      system function, 280
reverse function, 152, 153, 154
reverse sort function, 153
revision control, 441, 442, 469, 481
"right" as ambiguous name, 48
robustness of coding style, 3
$RS variable, 213

S[ Top ]
/s flag, 240, 241, 470
-s option, 306
\s* pattern, 250, 268, 269
\s+ pattern, 250, 266
$scalar argument, 170, 171
scalar reverse function, 153, 154
scalar variables
      angle brackets and, 167
      anonymous, 330, 331
      best practice, 476
      contextual return values, 188-191
      indices as, 14
      inside-out objects and, 330
      misreading, 12
      multi-contextual, 191-194
      nameless, 331
      open statement and, 204
      references and, 42
      return values, 186-188
      reversing, 153, 154
Scalar::Util module (CPAN)
      best practices, 471
      description, 487
      functions, 170, 174
      refaddr function, 330
      subroutines, 171
      utilities, 170
      weaken function, 234
Schwartzian Transform, 152, 164
"second" as ambiguous name, 48
SEE ALSO template, 138
seek function, 156
select function
      autoflushes and, 224, 225
      contextual return values, 189
      sleeping and, 168, 169
semantic consistency, 36
semicolons (;)
      best practice, 472
      broken expressions and, 29
      code layout and, 15, 17
      thin commas as, 68, 69
"set" as ambiguous name, 48
set_terseness( ) subroutine, 199
SHA-512 hash function, 150, 151
shift( ) method, 180, 339
shuffle( ) subroutine, 172, 491
$SIG variable, 430
%SIG variable, 430
@SIG variable, 430
single quotation (')
      empty strings and, 53
      heredocs and, 64
      single-character strings and, 54
      string delimiters and, 52
size( ) subroutine, 460, 461, 491
skip( ) subroutine, 407, 410
sleep function, 168, 169, 476
slices
      best practice, 474
      delete builtin and, 102
      empty, 89
      factoring, 90-92
      hash, 89, 90, 102, 193, 455
      layouts for, 90
      variables, 89
slurp( ) subroutine, 215, 408, 491
slurping
      best practice, 477
      filehandles, 213, 214
      input streams, 214-215
      IO::Prompt module and, 398
      line-based input and, 212, 213
Smart::Comments module (CPAN)
      debugging and, 439, 440
      description, 490
      progress indicators, 224
sort function
      contextual return values and, 189
      homogeneous list-returning subroutine, 190
      overview, 149-152
      package variables, 430
sorting
      automating, 164, 165
      best practice, 475, 476
      built-in functions and, 149-152
Sort::Maker module (CPAN), 164, 165, 490
sort_max_first( ) subroutine, 165
spaces
      best practice, 478
      builtins and, 13, 14
      empty strings and, 53
      identifiers and, 44
      indenting with, 20, 22
      keys and indices, 14
      keywords and, 11, 12
      named characters, 248
      regular expressions and, 249, 250
      subroutines and variables, 12
      vertical alignment and, 26
      /x mode and, 236
splice function, 189
split function, 157, 158, 159
SpreadSheet::ParseExcel module (CPAN), 418
sqrt function, 461, 462, 464
square brackets [ ]
      bracketing, 10
      lists and, 71
      metacharacters and, 247
      negative indices and, 88
      string delimiters and, 52
      vertical alignment of, 27
stat function, 191, 274
statements
      best practice, 474
      cascading if-elsif, 117
      C-style and, 100, 101
      factoring out long expressions, 29
      negative, 97-98
      paragraphs of, 23
      postfix modifiers, 96-97
      semicolons and, 15
      sharing lines, 22
*STDERR stream, 438
*STDIN stream, 216, 219
*STDOUT stream, 220, 438
strict module, 488
string boundaries, 239
:STRINGIFY method, 388
strings (see text strings)
sub keyword, 142
Sub::Installer module (CPAN), 163, 490
subroutine calls
      barewords and, 205
      complex mappings, 113-114
      error handling and, 276, 280
      extracting values, 105
      misreading, 11, 12
      parentheses and, 13
SUBROUTINE/METHODS template, 134
subroutines
      anonymous, 163
      argument lists, 178-181
      best practices, 470, 472, 476
      boolean values and, 40
      as builtins, 13
      caching and, 461, 462, 463
      call syntax, 175-177
      capitalization of, 45
      code layout and, 12
      contextual return values, 188-191
      conversion, 388
      declarative exporting and, 409
      decomposition and, 175
      default argument values, 185-186
      documenting, 141, 142
      exporting and, 407-410
      grammar rules, 40
      heredocs and, 62
      homonyms, 177, 178
      implicit returns, 197-199
      interface variables and, 411-414
      lvalues and, 346
      magic goto, 435
      memoizing, 152
      methods and, 338
      missing arguments, 184-185
      multi-contextual return values, 191-194
      name templates for, 37
      named arguments, 66, 182-183
      parentheses and, 176
      prototypes in, 194-196
      refactoring, 401-404
      regular expressions as, 236
      returning failure, 199, 201
      scalar return values, 186-188
      sub keyword, 142
      tied variables and, 452
      utility, 490-492
      wrapper, 181
      (see also utility subroutines)
subscripting
      best practice, 474
      necessary, 103-105
      unnecessary, 101-103
substr function
      arguments, 170
      fixed-width data and, 154
      four-argument substr, 166
      lvalue substr, 165, 166
      overview, 165, 166
substrings
      best practice, 476
      built-in functions and, 165, 166
      unpack function and, 155
suffixes, naming conventions, 41, 42, 46
sum( ) subroutine, 172, 491
SUPER pseudoclass, 389-393
Symbol module, 204
symbolic references, 230-231, 409, 430, 477
SYNOPSIS section (documentation), 311
SYNOPSIS template, 134
syntactic consistency, 36
system function, 274, 280, 281

T[ Top ]
.t file extension, 423, 424, 425
-T function, 106
\t instead of tab, 22, 53
t/ subdirectory, 416, 423, 424
tables
      array naming conventions, 43
      best practice, 475
      command-line processing and, 308
      look-up, 118-121, 455, 464
      regular expressions and, 259-261
      slice factoring and, 90
      ternary operator and, 32, 121-123
      vertical alignment, 26-27
tabs
      best practice, 472
      code layout and, 20, 22
      empty strings and, 53
tainted( ) subroutine, 171, 492
technical documentation, 133, 141, 475
templates
      BBEdit editor and, 485
      best practices, 469, 470, 475
      for comments, 141, 142
      creating modules, 416
      for documentation, 133-139
      grammar rules and, 37
      Smart::Comments module and, 224
      TextWrangler editor and, 486
Template::Toolkit module (CPAN), 418
terminal elements (arrays), 88
terminators, heredoc, 62-64, 473
ternaries
      best practice, 473, 475
      code layout, 31, 32
      tabular, 121-123
ternary operator (?:), 32, 121-123
test cases
      adding for bugs, 428
      best practices, 469, 481
      debugging and testing, 427-429
      failure, 425, 426
      overview, 420, 421
      scope of, 426
test suites
      best practice, 481
      failure and, 425
      fixing, 428
      overview, 424, 425
      scope of, 426
:TEST tagset, 410
Test::Harness module, 424, 425, 488
testing
      best practice, 481
      boolean names and, 40
      cascaded equality, 118-121
      eq comparisons, 271
      failed boolean, 197
      failure, 280, 281, 425, 426
      flags and, 124
      for interactivity, 218-220
      interfaces and, 398
      list membership, 71, 72
      missing argument and, 184-185
      modular, 407, 421-424
      negative control statements and, 97-98
      overview, 427-429
      print statements and, 276
      scope of, 426, 427
      strictures and, 433-436
      strings and, 457
      tabular ternaries and, 121-123
      use warnings pragma, 431, 432
      warning-free compilation and, 432
      (see also conditional tests; debugging)
Test::More module, 421-424, 471, 488
Test::Simple module, 421-424, 471, 488
Test::Tutorial module, 424
Test::Utils module, 408
text strings
      best practice, 473
      boundary anchors, 239
      comparisons, 271, 272
      contextual return values, 192
      conversion subroutines for, 388
      delimiters for, 51-53
      empty, 53
      end of string, 240
      evaluating, 161-164
      multiline, 60
      reversing characters in, 153
      single-character, 53, 54
      \t, 22
      testing and, 426, 457
      unrecognized identifiers as, 65
      vstrings as, 404
Text::Autoformat module (CPAN), 418, 490
Text::CSV module (CPAN), 490
Text::CSV::Simple module (CPAN), 160, 490
Text::CSV_XS module (CPAN), 158-161, 490
TextWrangler editor, 486
theredoc, 62
thin commas, 68, 69, 474
throw( ) statement, 94
throwing exceptions (see exception handling)
tied filehandles, 451-453
tied variables, 451-453
Time::HiRes module, 168, 488
Time::HiRes::usleep function, 168
total_size( ) subroutine, 460, 461, 492

U[ Top ]
unary operators, 15
underscore (_)
      best practice, 473
      identifiers and, 67
      naming conventions, 44
      readability and, 59, 60
      utility subroutines and, 49
uniq( ) subroutine, 173, 492
UNIVERSAL class, 379, 381
unless keyword, 96-99
unlock_hash( ) subroutine, 323
unlock_keys( ) subroutine, 323
unlock_value( ) subroutine, 323
unpack function, 154-157, 189
unpacking
      best practices, 470, 479
      command lines, 306
      exceptions, 296-298
until keyword, 96-99
--usage option, 303, 310, 311
USAGE template, 136
use base pragma, 360
use charnames pragma, 54
use constant pragma, 56, 57, 58
use English pragma
      best practices, 471
      comments and, 80
      match variables, 82
      punctuation variables and, 79
      slurping and, 213
      $WARNINGS variable, 431
use Fatal pragma, 279, 280
use IO::Handle pragma, 74
use only pragma, 407
use overload pragma, 388
use Readonly pragma, 56, 57
use strict pragma
      barewords and, 66, 176
      declarative exporting and, 409
      dereferencing and, 228
      encapsulation and, 329
      overview, 429-431
      symbolic references and, 230
      warning-free compilation and, 432
use version pragma, 404
use warnings pragma, 431, 432
user documentation, 133, 140, 147
usleep( ) subroutine, 168, 492
utilities, 170-174, 476
utility subroutines
      best practice, 473
      functionality, 181
      listed, 490-492
      naming conventions, 49
      writing, 223

V[ Top ]
value switches, 118-121, 475
values
      barewords, 65, 66
      best practices, 469, 473, 474, 478
      captured, 253
      constants and, 55-58
      empty strings, 53
      escaped characters, 54, 55
      extracting, 105
      fat commas, 66-68
      flags and, 302
      here documents and, 61
      heredoc indentation, 61-62
      heredoc quoters, 64, 65
      heredoc terminators, 62-64
      iterative list-returning subroutine, 191
      leading zeros, 58, 59
      list membership, 71, 72
      lists and, 71
      long numbers, 59, 60
      low-precedence operators, 70-71
      multiline strings, 60
      renaming, 105
      single-character strings, 53, 54
      string delimiters, 51-53
      tabular ternaries and, 121-123
      testing considerations, 426
      thin commas, 68, 69
values function, 102, 166
variables
      alias, 104
      array indices and, 88-89
      best practices, 470, 472, 474, 480
      boolean values and, 40
      breaking assignments, 30, 31
      caching and, 460
      capitalization of, 45
      capture, 253-257, 478
      code layout and, 12
      dollar-underscore and, 85-87
      exporting from modules, 409
      global, 82, 297, 449
      heredocs and, 62
      initialization, 78-79
      interfaces and, 409, 411-414
      interpolating, 51
      iterator, 96, 105-110, 474
      match, 82-84, 474
      name templates for, 37
      naming conventions, 38, 39
      package, 77
      punctuation, 81
      reference, 41, 42, 473
      slice factoring, 90-92
      slice layouts, 90
      slicing, 89
      tied, 451-453
      vertical alignment and, 26
      (see also lexical variables; package variables; punctuation variables; scalar variables)
variable-width data, 157, 158-161
verbose option (Carp), 284
version module (CPAN), 404, 405, 488
version numbers
      best practice, 480
      modules and, 404, 405
      requirements, 405-407
--version option, 303, 310
VERSION template, 134, 136
$VERSION variable, 404, 405, 406
vertical alignment
      best practice, 472
      code layout and, 26-27
      importance of, 24
      leading zeros and, 58
vi editor, 10, 18
vile editor, 483
vim editor, 21, 438, 482, 483
:void marker, 279, 280
vstrings, 404

W[ Top ]
wantarray function, 193
warehoused attributes, 324
warn function, 284
warn statement, 438
warnings
      best practices, 470, 481
      testing/debugging, 431, 432, 433
$WARNINGS variable, 431
weaken( ) subroutine, 171, 234, 492
WeakRef module (CPAN), 234
while statement
      checking CSV syntax, 160
      for loops and, 101
      implicit returns and, 198
      input loops and, 211-212
      module interfaces and, 399
      postfix looping and, 96-97
      readability, 97-98
      redo statement and, 128, 129
      Smart::Comments module and, 224
whitespace (see spaces)
WIFEXITED( ) subroutine, 281

X[ Top ]
x command, 438
/x flag
      best practice, 470
      brace delimiters, 243
      extended formatting, 236, 237
      tabular regexes, 260
X::EOF exception handler
      exception classes and, 293, 296
      OO exceptions and, 289
      unpacking exceptions, 296-298
XML, 446, 447
XML::Parser module (CPAN), 418, 490
/xms flag, 242, 467
.xs file extension, 442
xsubpp tool, 442

Y[ Top ]
YAML module (CPAN), 490

Z[ Top ]
\z anchor, 239, 240, 252, 470
zeros
      best practice, 473
      leading, 58, 59
      module interfaces and, 399
      testing considerations, 426
zip( ) subroutine, 173, 492

	

Zurück zu Perl Best Practices


Themen

Buchreihen

Special Interest

International Sites

O'Reilly China O'Reilly France O'Reilly USA O'Reilly Japan O'Reilly Taiwan