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

I'm trying to use the CPAN module Win32::Console. It loads and works OK as long as I do not have "use strict;" But when I do use strict, it says Bareword "STD_INPUT_HANDLE" not allowed while "strict subs" in use. The relevant lines of code are
use Win32::Console; my $cons = new Win32::Console STD_INPUT_HANDLE;
I've been using Perl for a while, but I admit I am hazy on most of the object code practices.

Replies are listed 'Best First'.
Re: Using Win32::Console
by Athanasius (Archbishop) on Apr 03, 2018 at 06:54 UTC

    Hello LloydRice,

    I can’t reproduce your problem:

    16:47 >perl -Mstrict -MWin32::Console -we "my $cons = new Win32::Conso +le STD_INPUT_HANDLE;" 16:47 >

    What versions of Perl and of Win32::Console are you using? (I’m using Win32::Console version 0.10 and running 64-bit Strawberry Perl 5.26.0 under Windows 8.1.)

    I am hazy on most of the object code practices.

    The preferred syntax is: my $cons = Win32::Console->new(STD_INPUT_HANDLE); (but I doubt that the syntax of the call to new has any bearing on the error message you are seeing).

    Update: The statement my $cons = new Win32::Console STD_INPUT_HANDLE; is an example of “Indirect Object Syntax” which is documented in perlobj#Invoking-Class-Methods.

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Actually, I tried it with and without the parens. Agreed, no bearing. I have Strawberry 5.26.0. I do not know how to get the version of Win32. I do not recall if I installed it at the same time as Perl or later. A line in \strawberry\perl\lib\win32API\File.pm says $VERSION='0.1203";

      Yesterday, I downloaded the current version from CPAN. Several places there refer to version 07 April 1997. But I do not know how to install the new one. The makefile in that download does not work. Somewhere there says to run "install bat" and "test.pl", but I see no such files.

        If you want to find the version of a module from the command line:

        perl -MSome::Module -le "print $Some::Module::VERSION";

        Or:

        cpan -D Some::Module

        Similarly to install modules, Strawberry ships with cpanm, so to install a module and it's dependencies:

        cpanm Some::Module
        There must have been an error in my first script. I rewrote the file and it seems to be OK. Thanks for the advice.