in reply to Re: Question about eval
in thread Question about eval

This was hinted at in a couple of the above replies, but combined with die (or croak) perl's eval provides a handy way to implement simple exception handling similar to the try/catch of other languages like Java and JavaScript.
# some code that might fail eval { open MYFILE, "> some_file.txt" or die $!; ... close MYFILE; }; # catch the "exception" if ($@) { print "Errors during file operation: $@\n"; }
For more, search for "exception" on CPAN; there are several modules that provide more elaborate exception handling mechanisms.