How to properly handle errors in Perl


I am trying to keep my command prompt from closing when there is an error in opening a file. I already tried the 'die' command, but that closes the command prompt right after the message is displayed. I want to be able to print an error message, wait a few seconds, then close or exit. Right now, I can get the code to wait before closing the prompt, but it never displays my error message:

open (LOG1, $file1) || (print "\n# Error in opening $file1, make sure it exists! #\n", sleep(3), exit);

You're misusing the comma operator - print doesn't print the error message, but the return value of exit()! Use semicolons instead.