Perl Style: Avoid Testing eof

  • Don’t use this: (deadlock)

        while (!eof(STDIN)) {
            statements;
        }
    
  • Use this instead:

        while (<STDIN>) {
            statements;
        }
    
  • Prompting while not eof can be a hassle. Try this:

       $on_a_tty = -t STDIN && -t STDOUT;
       sub prompt { print "yes? " if $on_a_tty }
       for ( prompt(); <STDIN>; prompt() ) {
            statements;
       }
    

Forward to Avoid Gratuitous Backslashes
Back to Using A Hash Instead of $$name
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub