in reply to Which "use" statements in a module do "bubble up" to the callers? [SOLVED]

A similar question was just asked. Modules like strict and warnings are lexically scoped pragmas that disappear at the end of the current block. It takes trickery to work around that behavior, and you probably don't want to go there. Have you looked at Modern::Perl? constant is file-scoped. If you want your constants visible outside the file where you define them, you need to use Exporter. Perl's module system is very flexible, but I'm afraid that means that it's not possible to give you a simple answer.
  • Comment on Re: Which "use" statements in a module do "bubble up" to the callers?

Replies are listed 'Best First'.
Re^2: Which "use" statements in a module do "bubble up" to the callers?
by Anonymous Monk on Aug 31, 2017 at 14:57 UTC
    constant is file-scoped.
    Sorry, that's wrong, it's package-scoped. Usual practice is to define one package per file, which is the source of my mistake.
      I believe that constants are implemented as functions and have package scope the same as other functions.
      C:\Users\Bill\forums\monks>type scope.pl use strict; use warnings; use constant PI => 3.14; my $pi = PI; package B{ my $pi = PI; } C:\Users\Bill\forums\monks>perl scope.pl Bareword "PI" not allowed while "strict subs" in use at scope.pl line +6. Execution of scope.pl aborted due to compilation errors.
      Bill
        True. Also, the value of a constant is copied into the lexical pad of any code that uses it, just like a literal. And 22/7 is a slightly better approximation of π than 3.14, but 4*atan2(1,1) is much better.