# Self-reproducing Spiral

Tyler F. Creelan creelan at engr.orst.edu
Mon Jul 15 21:43:02 CDT 2002

```Can anyone explain how this (very awesome!) perl code works?

"This self-reproducing code prints a turning spiral filled with it's own
code."

#!/usr/bin/perl
\$_='
\$q ="\                   47"; wh
ile                           (\$ ;=
\$z                +=              .5 ){
%c=           \$r=0;\$/ ="";whi         le(2
0+          \$z>(\$;+=.05)){\$c{int\$       _+ 2
6+         2*(\$              r+= .0       2) *
s          in\$                   ;}{1       -\$_
+1         0+           int        \$r*c       o s
\$         ;}         =1for(0.       .1)        }\$
t        =r         ever se;\$        /.        =`
c        le        ar     `.         "         #!
/        usr       /bi             n/         pe
rl       \n\       \$_ =\$q        \n"          ;
fo        r\$y        (1..20){\$c{\$_}          {
\$ y       }? \$         /.=chop\$t            :
(\$/        . ="                          \4
0")         for(0.                    .53)          ;
\$/.        ="\n"}pri            nt"\$/\$          q;
s; ".         chr(9 2)."s;;g;eval\n           "}

';s;\s;;g;eval

Source: http://www.perlmonks.org/index.pl?node_id=176043

Also a Win32 version:

#!/usr/bin/perl
\$_='
\$q ="\                   47"; wh
ile                           (\$ ;=
\$z                +=              .5 ){
%c=           \$r=0;\$/ ="";whi         le(2
0+          \$z>(\$;+=.05)){\$c{int\$       _+ 2
6+         2*(\$              r+= .0       2) *
s          in\$                   ;}{1       -\$_
+1         0+           int        \$r*c       o s
\$         ;}         =1for(0.       .1)        }\$
t        =r         ever se;\$        /.        =`
c        le        ar     `.         "         #!
/        usr       /bi             n/         pe
rl       \n\       \$_ =\$q        \n"          ;
fo        r\$y        (1..20){\$c{\$_}          {
\$ y       }? \$         /.=chop\$t            :
(\$/        . ="                          \4
0")         for(0.                    .53)          ;
\$/.        ="\n"}pri            nt"\$/\$          q;
s; ".         chr(9 2)."s;;g;eval\n           "}

';s;\s;;g;eval

TIMTOWTDI

```