Actually, no, it's not a matter of taste. It's best to avoid eval STRING whenever possible since it forces dynamic runtime recompilation, and is thus rather slow. An eval BLOCK is always preferable. If you can represent the package names as literals (barewords) within your program, use this:
if (something()) {
eval {
require Text::CSV;
Text::CSV->import;
}
} else {
eval {
require Text::CSV_XS;
Text::CSV_XS->import;
}
}
The eval BLOCK syntax as well allows you to catch any fatal errors, storing them in $@:
die "Couldn't load module: $@" if ($@);
|