You should always perform all error checking in any language to ensure
that your program, if it fails, declines gracefully. One of the
greatest shortcomings of C is that error checking is entirely manual,
and you simply must, in every real-world application, check the return
value of almost every function. Perl is no different. If the result of
the statement fails in such a way that your program cannot continue, you
must check for the error and deal with it appropriately. If you need to
write the output of the program to a file and it can't be opened, then
you need to print it to the terminal or abort, or both, or at least
inform the user of the condition. People single out open probably
because it's so common and when it fails it's almost always a
show-stopping error. Ultimately, in good programming practice, you
should sanity check the result of any function that could make or break
your application. There are, obviously, some exceptions (I had to build
a C program once for which speed was the #1 priority, which meant going
light on error checking ), but that's just a good general rule.
Harry Putnam wrote:
Thanks for tips posters..
"John W. Krahn" <[EMAIL PROTECTED]> writes:
You should _always_ verify that the file opened successfully.
open(FILE,">somefile") or die "Cannot open 'somefile' $!";
Not being argumentative here but I've seen this said before. Not
really sure why it is important. I mean why is the open action
singled out for this protection. It seems other actions could also
cause a misfired script?
print FILE "An extra numeral <" . &lctime . "> appears\n";
^
You shouldn't use ampersands unless you need the different behavior they
provide.
print FILE "An extra numeral <" . lctime() . "> appears\n";
I use them simply for recognition in my own code. I wasn't aware of
different behavior from the () indicator. Can you aim me at some
documentation for elaboration?
You should probably be using POSIX::strftime instead which is simpler
and faster.
Thanks.
--
Benjamin J. Siders
Software Engineer
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]