Of course there is nothing to stop you from just mangling the symbol table at runtime. It is not a specifically compile time practice. (Come on try it,.. all the cooool kids are doing it) And with a little creativity and just the right amount of insanity you could make this work.

I saw this trick in Hook::LexWrap, by TheDamian, its quite simple really and very elegant. The code would look something like this:

use Bling; $x = $$; ## Bling Bling as before { my $no_bling = Bling->off(); $y = $$; ## no Bling Bling } $z = $$; ## Bling Bling as before
The magic (oooohhhh spooky) is that the variable $no_bling is lexically scoped. It is also an object instance. When the object is created in Bling->off() it unties $$. The DESTORY method of the object instance then re-tie's $$. Since DESTROY will get called at the close of the block,... whalla,.. you get lexically scoped insanity.

If you dont like the Bling->off() syntax, then you could try something witty with the indirect object syntax. buh_bye Bling or something like that. (although you can't use "no" cause perl will confuse it with the real "no")

Of course, no one in their right mind would do such a thing. No no,.. never,... never ever,.. no ,.. stop,.. dont make me,.. nooooooooooo......

-stvn

Disclaimer: In no way does this post consitute an endorsement of the practice of mangling perl's global variables. Bad,.. very very Bad.


In reply to Re: Lexical use/no Module? by stvn
in thread Lexical use/no Module? by Stevie-O

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.