Hello tkguifan,
To determine the platform on which the script is running, you can use either the built-in variable $^O (also spelled $OSNAME; see perlvar#General-Variables) or $Config{osname} from Config. See the recent thread Cross-platform accented character file names sorting, which also discusses the correct syntax for using the if pragma.
To test whether or not a module is present in the system, use or require it in an eval and then immediately test the value of $@:
22:42 >perl -wE "eval qq[use Unknown;]; say $@ ? 'failed' : 'succeeded +';" failed 22:43 >perl -wE "eval qq[use Data::Dump;]; say $@ ? 'failed' : 'succee +ded';" succeeded 22:56 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Conditional use of modules
by Athanasius
in thread Conditional use of modules
by tkguifan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |