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