in reply to Re^2: Using Win32::SerialPort in a module
in thread Using Win32::SerialPort in a module

Also the "my" was removed from the @ISA and @EXPORT global arrays

Oh, I missed in your original code that you used 'my' when it should have been 'our'. The 'our' keyword declares a global package variable1, where 'my' declares a lexical variable that can't be seen by Exporter afterward.

As Corion pointed out, you should put back strict and warnings (which will still work once you declare the variables with 'our'), and use Exporter 'import'; is cleaner than messing with our @ISA=('Exporter').


(1) Actually, 'our' adds a global package variable into your lexical scope, which is a little bit different from "declaring a global".

Replies are listed 'Best First'.
Re^4: Using Win32::SerialPort in a module
by Danny (Chaplain) on Sep 06, 2024 at 14:32 UTC
    (1) Actually, 'our' adds a global package variable into your lexical scope, which is a little bit different from "declaring a global".

    Technically, it creates an alias to a package variable, so 'our $foo' is an alias for '$Package::foo'. The purpose is so that you can say '$foo = 10' under 'use strict' instead of having to say '$Package::foo = 10'.