The 'no warnings' and 'no strict' have lexical scope; they are in effect only until the enclosing block ends. However, when I tried 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; }
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;
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?#!/usr/bin/perl -l # blingtest.pl use Bling; $x=$$; print '$x is ', $x; { no Bling; $y=$$; print '$y is ', $y; } print '$$ is ', $$;
$"=$,,$_=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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |