KW.pm Perl Style Guides #18

Slash Style Guide: Style 3

  • Operators

        $value = $foo || $bar;
        open(FILE, $file) or die $!;
  • 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 die $!;      # right
        die $! unless open(FILE, $fh);  # wrong
        print "Starting\n" if $verbose; # right
        $verbose && print "Starting\n"; # wrong
  • use here-docs instead of repeated print statements

                print <<THERE;
        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.
        THERE
  • But remember, THERE is interpolated while 'THERE' isn't. So escape $ or @.

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