Using die() to trap errors in Perl

The easiest way to use the die() function is with a logical OR when opening a file.

open (MYFILE, ">thefilename") or die "Cannot open file 'thefilename': $!";

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.