On top of the other points made here I thinks its worth pointing out that subs are essentially package variables that our() doesnt care about (it turns out there are quite a few of them *Globs are exempt from strict as are Fully::Qualified::Items and the punctuation and magic vars). And in fact the magic involved in your example (that of exporting subs) exploits this fact. Consider this

use strict; *foo=sub{print "foo"}; foo();

Which is in fact very close to what that use Module qw(fubar); actually does behind the scenes. When perl sees use Module qw(fubar); it doesnt think to itself "they want to alias Module::fubar() to main::fubar()" or any such declaration. Instead perl just thinks "oh, they want to pass an argument to that funny looking subroutine that happens to be a file full of subroutines, including one called import() which is in fact where I shall pass those arguments" and once the arguments are passed to import(), what import() does with them is entirely up to it. As it happens normally the result is that a line like

*"${pack}::${name}"=\&fubar;

Which is just an assignment that happens to set up the symbol table in such a way that it results in the appearance of the subroutine being "exported", which of course it isnt, it stays right where it is, and just pretends to be in both packages (if it was in fact a closure it would still be bound to the context inside the other module.)

Youll find that a lot of stuff in perl that has to do with package variables doesnt play quite as you might expect with strict, filehandles, formats etc.


---
demerphq

<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

In reply to Re: "use strict" not too strict by demerphq
in thread "use strict" not too strict by Mur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.