Update: removed unused confess
Update: to clarify, this will prevent the performance degradation that occurs through use of $&, $', and $` (so long as AmpKiller is use'd before code that uses one of the variables is even compiled). It also will croak if code actually tries to use one of the variables at run-time. If you do:
no croak will be done, since $& didn't actually get used.use AmpKiller; if ("foo" =~ /bar/) { print $& }
package AmpKiller; # usage: # eval $some_code_that_may_use_dollerampersand; # die "Sorry, can't do that: $@" if $@ && $@=~/Use of .* disallowed/; use strict; use warnings; use Carp 'croak'; sub TIESCALAR { my $var = $_[1]; bless \$var } sub FETCH { croak "Use of ${$_[0]} disallowed" } sub STORE { croak "Modification of a read-only value attempted" } tie our $amp, __PACKAGE__, '$&'; tie our $backtick, __PACKAGE__, '$`'; tie our $tick, __PACKAGE__, '$\''; $::{"&"} = *amp; $::{"'"} = *tick; $::{"`"} = *backtick; 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: AmpKiller.pm to disallow $&, etc.
by Abigail-II (Bishop) on Jan 27, 2004 at 09:38 UTC | |
by ysth (Canon) on Jan 27, 2004 at 17:10 UTC |