in reply to Defining a subroutine one of two ways depending on whether a package exists
You can do something like this:
BEGIN {
eval {
require Compress::Zlib;
import Compress::Zlib 'crc32'; };
*myCRC = $@ ? sub { 0 }: sub { crc32(@_) };
}
}
Actually "eval" works like error handling and even after wrong in statment inside eval it does not die and thier returned result can be track using $@.
Originally posted as a Categorized Answer.
|
|---|