YAPC::NA 2004 Perl Style Guides for Large Projects #20

Slash Style Guide: Style 3

  • Operators as logic shortcuts are fine

        $value = $foo || $bar;
        open($fhandle, $filename) or &warn("Can't open file $file. $!");
  • but don't use and instead of if where if is clearer:

        foo($bar) and baz($buz);  # wrong
        baz($buz) if foo($bar);   # right
  • compound statements: put the primary action first:

        open(FILE, $fh) or &error ($!);      # right
        &error($!) unless open(FILE, $fh);   # wrong
  • use here-docs instead of repeated print statements

    • <<especially since HTML does not display repeated whitespace>>

                print <<EOT;
        This is a whole bunch of text.
        I like it.  I don't need to worry about messing
        with lots of print statements and lining them up.
        EOT

<< Previous | Index | Next >> Copyright © 2004 Daniel Allen