in reply to Defensive Programming

One thing that I've trained myself to do, which isn't so much defensive programming in construction, but more of a habit, is to mirror resource calls right away. For instance, if I'm writing code to process a file, I'll write:

open FILE, "<$filename" or die "Can't open $filename: $!\n"; close FILE or die "Can't close $filename: $!\n";
and then fill in the code between the open and the close. (And yes, 3-arg open is safer, but it's not available on my target.) I do the same thing with DBI connects and the like.

--
:wq

Replies are listed 'Best First'.
Re: (FoxUni) Re: Defensive Programming
by theorbtwo (Prior) on Jan 15, 2002 at 00:42 UTC

    One of my defensive programming steps is to /always/ use IO::File whenever I open a file. Scoping is a wonderful way to close files, and it keeps me from having to remember puncuation variables, and having to use bareword filehandles, and ...

    Of course, if you can't 3-arg open, you probably can't use IO::File either.

    Thanks,
    James Mastros,
    Just Another Perl Scribe