![]() |
|
Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
use executes at compile time, before your if statement even gets evaluated. The result of that is that use DBI happens on all platforms, not just Linux. Instead you need to load the module with require, a la:
There's a module called if, which is part of the core Perl distribution. It wraps up the above pattern allowing you to use the somewhat neater:
It's worth noting that this is not some kind of extension to Perl's syntax. You're simply useing the if module and passing its import method two parameters: the first is a boolean (the result of evaluating $^O eq 'Linux'); the second is a module name as a string. The if module then contains the logic to load the named module only if the boolean is true.
use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
In reply to Re: Include a package based on OS.
by tobyink
|
|