Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Using use itself -- file scope !?

by jakobi (Pilgrim)
on Oct 29, 2009 at 19:39 UTC ( [id://804035]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using constants...
in thread Using constants...

ikegami's right as a BEGIN{require 'constants.pl'} (thanx!) or even a simple peek at %main:: does show.

But I'm still wondering about this section in perldoc -f use:

Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Currently implemented pragmas are:
      use constant;
      use diagnostics;
      use integer;
      use sigtrap  qw(SEGV BUS);
      use strict   qw(subs vars refs);
      use subs     qw(afunc blurfl);
      use warnings qw(all);
      use sort     qw(stable _quicksort _mergesort);
Some of these pseudo-modules import semantics into the current block scope (like "strict" or "integer", unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).

Let me attempt to make sense of it:

Now a BEGIN{require "constants.pl"} basically turns contents.pl into a module. Add a do "y" somewhere near the end in main.pl. Create this file y and have it just print STDERR keys %main::. Copy it to a file z and prepend BEGIN{do "main.pl"}. Run perl -e ./z. Wonder. Check Exporter documentation and do a similar little test with imported symbols. And start WONDERING.

  • use strict; obviously is well behaved and doesn't mess with other files or blocks outside its enclosing lexical scope. Ok. Should the same for stuff like integer et al.
  • Function definitions in %main:: are valid beyond the end of the file.
  • If file A requires a file B, which in turn says 'use ... qw/function/;', the function by default is visible also in the file A. Using Exporter doesn't localize things, and the imported functions and symbols are also visible in files other than the file containing the actual use statement (read: way beyond end of enclosing file).

I'm now fully confused, and it's not the missing parens in the quoted section above:

  • What does the above quote from perldoc -f use try to say?
  • What exactly might effective through the end of file refer to? Especially given the the mention of ordinary modules!?
  • What kind of (importing symbols in package name space from?) ordinary modules has file scope!?

Any ideas on what is actually meant?

cu & thanx, Peter -- --INT due to confusion spell.

Replies are listed 'Best First'.
Re^4: Using use itself -- file scope !?
by ikegami (Patriarch) on Oct 29, 2009 at 20:26 UTC

    What does the above quote from perldoc -f use try to say?

    Some modules are pragmas. pragams affect the behaviour of code scope in which they are used rather than provide subs.

    What kind of ordinary modules has file scope!?

    Since you're using "ordinary" to mean not like a pragma, none do by definition.

    What exactly might effective through the end of file refer to?

    It equates end of file with end of the package, and thus to the end of the visibility of the imported functions.

      Thanx, ikegami.

      Reading your #3 finally makes sense of the paragraph; implicit assumption of the most simple usage style of the package statement of one per file, never to reoccur in any other file (probably this 'file scope' shouldn't even be mentioned in this section at all).

      Provided that this tripped at least me for sure, do you think this large enough to warrant trying a patch/rewrite of this documentation section?

      I wouldn't mind trying myself for (hubris &) learning experience, but I'd certainly need some hand holding when I've found the source pods and did some reading on p5p and patch submission (warn "non-native speaker combined with utter lack of p5p experience...\n").

      cu & HTH, Peter -- hints may be untested unless stated otherwise; use with caution & understanding.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-29 07:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found