Takamoto has asked for the wisdom of the Perl Monks concerning the following question:

I have a very stupid question...

I need to call 'use' in a conditional statement. I do it normally like this:

use if $VersionOS eq 'Win', DBD::ODBC;

What is if need to use the following:

use if $VersionOS eq 'Win', Win32::OLE 'CP_UTF8';

This of course does not work.

Replies are listed 'Best First'.
Re: use conditional
by hippo (Archbishop) on Dec 12, 2019 at 16:27 UTC

    You are missing the (fat) comma:

    use if $VersionOS eq 'Win', Win32::OLE => 'CP_UTF8';

    From the documentation for if the syntax seems clear.

      use if $VersionOS eq 'Win', Win32::OLE => 'CP_UTF8';

      Note that this doesn't work under strict because Bareword "Win32::OLE" not allowed while "strict subs" in use; the :: prevents the LHS of the fat comma being autoquoted. So:

      use if $VersionOS eq 'Win', 'Win32::OLE' => 'CP_UTF8'; # or use if $VersionOS eq 'Win', 'Win32::OLE', 'CP_UTF8';
      Thank you!
Re: use conditional
by BillKSmith (Monsignor) on Dec 12, 2019 at 16:14 UTC