A friend of mine showed me:
http://www.thinkgeek.com/stuff/docs/perl-camel-source.shtml
a camel-shaped program that prints four camels when run, and
asked could I do better using CPAN Acme::EyeDrops module.
Well, I don't know about better, but I could not restrain
myself from trying something similar.
The EyeDrops-generated camel.pl, shown below, can generate
thirty two different camels as follows:
perl camel.pl normal camel
perl camel.pl q quine (program prints itself)
perl camel.pl m mirror (camel looking in the mirror)
perl camel.pl i inverted camel
perl camel.pl u upside-down camel
perl camel.pl r rotated camel
You can further combine the above options, each combination
producing a different camel, for example:
perl camel.pl uri
The 32 possible combinations are:
"" q r u m i
qr qu qm qi ru rm ri um ui mi
qru qrm qri qui qum qmi rum rui rmi umi
qrum qrui qumi qrmi rumi
qrumi
camel.pl was generated from this program, gencamel.pl:
use Acme::EyeDrops qw(sightly);
my $prog = sightly( { Regex => 1,
Shape => 'camel',
SourceString => <<'END_SRC_STR' } );
$:=pop||'';open$%;chop(@;=<0>);$:=~/r/&&(@;=map{$-=$_+$_;join"",
map{substr$_,$-,1}@;}$%..$;[8]=~y;;;c/2);$:!~/q/&&y,!-~,#,,$:=~/m/
&&($_=reverse),$:=~/i/&&y, #,# ,,print$_.$/for$:=~/u/?reverse@;:@;
END_SRC_STR
my @a = split(/\n/, $prog);
my $max = 0; length > $max and $max = length for @a;
$_ .= ' ' x ($max - length) for @a; $\ = "\n";
print ' ' x ($max+2); print " $_ " for @a; print ' ' x ($max+2);
with the command:
perl gencamel.pl >camel.pl
I had to work quite hard to make the source program small enough to
fit into a single camel (and it won't fit into a single `/anick), so
I would be delighted if any golfers out there can further shorten:
$:=pop||'';open$%;chop(@;=<0>);$:=~/r/&&(@;=map{$-=$_+$_;join"",
map{substr$_,$-,1}@;}$%..$;[8]=~y;;;c/2);$:!~/q/&&y,!-~,#,,$:=~/m/
&&($_=reverse),$:=~/i/&&y, #,# ,,print$_.$/for$:=~/u/?reverse@;:@;
Enjoy,
/-\ndrew
camel.pl:
(Save all text between ----- lines below, including
leading and trailing space-filled lines)
-------------------------------------------------------------------
''=~('('.'?'
.'{'.( '`'|'%').("\["^
'-').('`'| '!').('`'|',').'"'
.'\\'.'$'. (':'). '='.('['^'+').("\`"|
'/').('['^'+')."\|". '|'."'"."'".';'.("\`"|
'/').('['^'+').("\`"| '%').('`'|'.').'\\'.'$'
.'%'.';'.('`'|'#'). ('`'|'(').('`'|'/').("\["^
'+').'('.'\\'. '@'.';'.'='.'<'.('^'^('`'|'.'
)).'>'.')'.';' .'\\'.'$'.':'.'='.'~'.'/'.("\["^
')').'/'.('&'). '&'.'('.'\\'.'@'.';'.'='.('`'|'-').
('`'|'!').('['^ '+').'\\'.'{'.'\\'.'$'.'-'.'='.('\\').
'$'.'_'.'+'.''. '\\'.'$'.'_'.';'.('`'|'*').('`'|('/')).(
'`'|')').('`'| '.').'\\'.'"'.'\\'.'"'.','.('!'^'+').('`'
|'-').('`'|'!' ).('['^'+').'\\'.'{'.('['^'(').('['^'.').(
'`'|'"').('['^'(').('['^'/').('['^')').'\\'.'$'.'_'.(',').
'\\'.'$'.'-'.','.('^'^('`'|'/')).'\\'.'}'.'\\'.'@'.';'.'\\'
.'}'.'\\'.'$'.'%'.'.'.'.'.'\\'.'$'.';'.'['.(':'&'=')."\]".
'='.'~'.('['^'"').';'.';'.';'.('`'|'#').'/'.('^'^('`'|','))
.')'.';'.'\\'.'$'.':'.'!'.'~'.'/'.('['^'*').'/'.'&'.('&').(
'['^'"').','.'!'.'-'.'~'.','.'#'.','.','.'\\'.'$'.':'.'='.
'~'.'/'.('`'|'-').'/'.('!'^'+').'&'.'&'.'('.'\\'.'$'. '_'
.'='.('['^')').('`'|'%').('['^'-').('`'|'%').("\["^ ')'
).('['^'(').('`'|'%').')'.','.'\\'.('$'). ':'.'='. '~'
.'/'.('`'|')').'/'.'&'.'&'.('['^"\""). (',').( '{'
^'[') .'#'.','.'#'.('{'^'[').','.',' .("\["^ '+'
).('['^')').('`'|')').(('`')| "\.").( '['
^('/')). '\\'."\$". ('_'). ('.'). ((
'\\')). '$'.'/'. ("\`"| '&').( ((
"\`"))| ('/')).( "\["^ ')'). (
'\\'). '$'.':'. '='. '~'.
"\/".( '['^'.'). '/'. '?'.
('['^ (')')).( '`'| '%')
.('[' ^'-').( '`'| '%')
.''. ("\["^ ')') .''.
('[' ^(( '(') )).(
'`'| '%' ).+ (((
((( ((( ((( (((
((( ((( ((( (((
((( ((( ((( ((
(( '\\')) ))
)) ))))) ))
)) )))))))) ))
))) )))) ))))) ))
).+ ('@'). ';'. ':'
.''. '\\'.'@' .(( ';')
).('!' ^'+').
'"'.'}'. ''.')')
-------------------------------------------------------------------