Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Bareword issue with Perl 5.34

by Corion (Patriarch)
on Oct 11, 2021 at 14:58 UTC ( #11137419=note: print w/replies, xml ) Need Help??

in reply to Bareword issue with Perl 5.34

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);

Replies are listed 'Best First'.
Re^2: Bareword issue with Perl 5.34
by Anonymous Monk on Oct 11, 2021 at 17:24 UTC

    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 ); }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2023-10-03 06:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found