in reply to Logic for importing and strict vars?

Subs are special, perl doesn't care so much if a function is declared to allow it to be called, this is valid:

perl -cE "use strict; use warnings; myFunction()" -e syntax OK
For the code to work you just need to have a function in the *::myFunction slot at execution time. So I guess this is why the second line works?

Now for the last one, tye's post actually has the answer:

when the variable slot of a glob gets assigned to by code compiled into another package
For the import to be valid, the glob as to be written from another package.

Replies are listed 'Best First'.
Re^2: Logic for importing and strict vars?
by haukex (Archbishop) on Feb 28, 2019 at 08:53 UTC
    Subs are special, perl doesn't care so much if a function is declared to allow it to be called

    Yes, although the parens are significant in your example (which is why mine left them out):

    $ perl -wMstrict -e 'BEGIN { *::x=sub{} } x' $ perl -wMstrict -e 'BEGIN { *::x=sub{} } x()' $ perl -wMstrict -e ' { *::x=sub{} } x()' $ perl -wMstrict -e ' { *::x=sub{} } x' Bareword "x" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -wMstrict -e 'x' Bareword "x" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -wMstrict -e 'x()' Undefined subroutine &main::x called at -e line 1. $ perl -wMstrict -e '&x' Undefined subroutine &main::x called at -e line 1.