Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Bareword issue with Perl 5.34

by Anonymous Monk
on Oct 11, 2021 at 14:52 UTC ( #11137418=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks

Loading the following does not produce any issue with Perl 5.28.

use strict; use warnings; $Win32::OLE::CP = CP_UTF8;

It produces issues however with Perl 5.34:

Bareword "CP_UTF8" not allowed while "strict subs" in use at l +ine 3. Execution of aborted due to compilation errors.

Changing $Win32::OLE::CP = CP_UTF8; to $Win32::OLE::CP = 'CP_UTF8'; avoid Perl complaining, however the feature is no more loaded. What is the best approach to solve this?

Replies are listed 'Best First'.
Re: Bareword issue with Perl 5.34
by Corion (Patriarch) on Oct 11, 2021 at 14:58 UTC

    I'm not sure why the code would work in Perl 5.28 as given, but for your problem see the Module Options of Win32::OLE. The new syntax to use is

    use Win32::OLE; Win32::OLE->Options(CP => Win32::OLE::CP_UTF8);

    Alternatively, you can make the CP_UTF8 constant known by importing it explicitly from Win32::OLE:

    use Win32::OLE 'CP_UTF8'; Win32::OLE->Options(CP => CP_UTF8);

      Thank you for your reply. I am starting to think that the issue is somewhere else. My .pl script should run both on macOS and on Windows. Obviously, when on it is run on macOS, the Win32::OLE should be skipped. I solved this like this:

      use if $^O eq 'MSWin32', 'Win32::OLE'; if ( $^O eq 'MSWin32' ) { $Win32::OLE::CP = 'CP_UTF8'; }

      Or compacter:

      use if $^O eq 'MSWin32', 'Win32::OLE::CP' => 'CP_UTF8';

      On macOS the scripts load correctly and Win32::OLE stuff is skipped. If I use the same without '' or any of your suggestions, I get the Bareword "CP_UTF8" error. Am I everseeing something?

        I think you want

        use if $^O eq 'MSWin32', 'Win32::OLE', 'CP' => 'CP_UTF8';

        That is still the "old" way of using Win32::OLE. The new way would be something like:

        use if $^O eq 'MSWin32', 'Win32::OLE'; if( $^O eq 'MSWin32' ) { Win32::OLE->Options( CP => 'CP_UTF8' ); # or maybe # Win32::OLE->Options( CP => Win32::OLE::CP_UTF8 ); }
Re: Bareword issue with Perl 5.34
by Fletch (Bishop) on Oct 11, 2021 at 19:56 UTC

    Something's wonky because I tried with 5.26.1 and 5.32.1 (which is what I had installed handy) and both griped with the (expected, due to strict) bareword not allowed. Longshot (and this is really straw-grasping) but you might check your PERL5OPT environment variable and maybe see if you've got something that might be pulling something in and defined CP_UTF8 wherever your 5.28 is (presuming this is on different machines with different environments; if it's the same box / same user / same environment . . . it is a puzzlement).

    Addendum: Not that you've not already worked out the solution, but if you're trying to track down what's happening . . .

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11137418]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-11-30 04:50 GMT
Find Nodes?
    Voting Booth?