| Acme-Palindrome documentation | Contained in the Acme-Palindrome distribution. |
Acme::Palindrome - Programs are the same backward and forward
use Acme::Palindrome; print "Hello world";
The first time you run a program under use Acme::Palindrome, the module reverses the code in your source file from top to bottom, left to right. The code continues to work exactly as it did before, but now it looks like this:
use Acme::Palindrome; ;"dlrow olleH" tnirp
Acme::Palindrome could not access the source file to modify it.
Acme::Bleach - Code and documentation nearly taken verbatim.
Casey West <casey@geeknest.com>
Copyright (c) 2003, Casey West. All Rights Reserved. This module is free software. It may be used under the same terms as Perl itself.
| Acme-Palindrome documentation | Contained in the Acme-Palindrome distribution. |
package Acme::Palindrome; # $Id: $ use strict qw[vars subs]; use vars qw[$VERSION $TIE]; $VERSION = (qw$Revision: 0.1$)[1]; $TIE = " \t"x8; sub backward { "$TIE\n".palindrome(split "\n", $_[0])."\n" } sub forward { palindrome(split "\n", $_[0]) } sub is_forward { $_[0] !~ /^$TIE/ } sub is_backward { $_[0] =~ /^$TIE/ } open 0 or print "Can't reverse '$0'\n" and exit; (my $code = join "", <0>) =~ s/.*^\s*use\s+Acme::Palindrome\s*;\n//sm; local $SIG{__WARN__} = \&is_forward; do {eval forward $code; exit} if is_backward $code; open 0, ">$0" or print "Cannot reverse '$0'\n" and exit; print {0} "use Acme::Palindrome;\n", backward $code and exit; sub palindrome { my $max = 0; length > $max && ( $max = length ) for @_; return join "\n", map sprintf( "%${max}s", scalar reverse $_ ), reverse @_; } 1; __END__