in reply to Re^2: using a variable to specify which perl module to use (bareword)
in thread using a variable to specify which perl module to use
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 ($@);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: using a variable to specify which perl module to use (bareword)
by tye (Sage) on Jul 15, 2003 at 19:14 UTC |