In a perl script, you can do this;
use strict; # hacksym('name', ref) # e.g. hacksym('foo', \@bar) makes @foo an alias for @bar sub hacksym { my $name = shift; my $ref = shift || die "need a reference!"; no warnings 'uninitialized'; no strict 'refs'; *{$name} = $ref; }
The 'no warnings' and 'no strict' have lexical scope; they are in effect only until the enclosing block ends. However, when I tried this:
(beware, this contains syntax that may frighten small children)
package Bling; use strict qw(vars subs); use warnings; # simply put: use Bling; then, whenever your script accesses $$, # it prints 'Bling Bling!!'. my $ref; sub import { unless (defined $ref) { $ref = \${'main::$'}; undef *{'main::$'}; # tramples @$ and %$. I really don't ca +re. tie ${'main::$'}, 'Bling::Bling'; } } sub unimport { if (defined $ref) { untie ${'main::$'}; *{'main::$'} = $ref; undef $ref; } } package Bling::Bling; sub TIESCALAR { bless [], shift; } sub FETCH { local $\; print "Bling Bling!!\n"; $$ref; } 1;
#!/usr/bin/perl -l # blingtest.pl use Bling; $x=$$; print '$x is ', $x; { no Bling; $y=$$; print '$y is ', $y; } print '$$ is ', $$;
The result is that no 'Bling Bling!!'s are printed, because the 'no Bling' is not lexically scoped. My question is this: Is it possible to achieve 'lexicality' of use/no in my own modules, just like strict.pm and warnings.pm do?
--Stevie-O
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc

In reply to 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.