[tpm] What does this line of Perl code mean?

Indy Singh indy at indigostar.com
Thu Mar 18 14:53:16 PDT 2010


Hi all,

What does the following line of code mean and why is it needed?
local $SIG{__WARN__} = \&dirty;

It is part of Acme::Bleach which is below.

For bonus points what is the purpose of $tie?

package Acme::Bleach;
$VERSION = '1.12';
my $tie = " \t"x8;
sub whiten { local $_ = unpack "b*", pop; tr/01/ \t/; s/(.{9})/$1\n/g; 
$tie.$_ }
sub brighten { local $_ = pop; s/^$tie|[^ \t]//g; tr/ \t/01/; pack "b*", 
$_ }
sub dirty { $_[0] =~ /\S/ }
sub dress { $_[0] =~ /^$tie/ }
open 0 or print "Can't rebleach '$0'\n" and exit;
(my $shirt = join "", <0>) =~ s/.*^\s*use\s+Acme::Bleach\s*;\n//sm;
local $SIG{__WARN__} = \&dirty;
do {eval brighten $shirt; exit} unless dirty $shirt && not dress $shirt;
open 0, ">$0" or print "Cannot bleach '$0'\n" and exit;
print {0} "use Acme::Bleach;\n", whiten $shirt and exit;
__END__


Indy Singh
IndigoSTAR Software -- www.indigostar.com 



More information about the toronto-pm mailing list