CN Perl Advent Calendar 2009-12-09

Have Fun

by Fayland Lam

本文存属玩乐。

Acme::Pony

use Acme::Pony;
print "Hello world";

将上文保存为 hello.pl, 然后运行 perl hello.pl, 最后打开 hello.pl 你会发现整个文件都变了。变成了:

use Acme::Pony;
         bu                       
        ffYBUf                    
       fYbuFFYbU                  
      ffYbUFfyBUF                 
     fYBuffYbUFFy                 
      buffyBuffYb                 
       ufFybuffYbu         Ff     
       YbUffYBuffYB       uFFyb   
  uFFyBUfFYBUfFYbuffybUffYBUfFY   
 BuFFYBuFFybUffYBUffyBUfFYbufFyb  
 UFf  yBuffYbuFFyBUFfybUfFybuffY  
  bUf     fybUffyBUffYBuFFYbufFyB 
           uffy      BUFFYbUfFYBUF
           fYbU       fFybuFfyBUFf
           yBu          ffYbufFyBU
           FFY        bUf FYBUFfY 
           bXX            XXX XXX 
          XX              XXX     
         XXX             XXX

更惊奇的事情还在后头,重新运行 perl hello.pl, 你会发现它输出了 "Hello world". :)

如果上述还不够过瘾,试试下面的。

编辑一个 hello.pl

print "Hello World\n";

然后创建一个 havefun.pl, paste 如下代码:

use Acme::EyeDrops qw(sightly);
print sightly( {
    Shape       => 'camel',
    SourceFile  => 'hello.pl',
    Regex       => 1
} );

完毕后运行 perl havefun.pl > hello2.pl

打开 hello2.pl, 你会发现一只大骆驼

                                      ''=~('('.'?'
           .'{'.(                   '`'|'%').("\["^
        '-').('`'|                '!').('`'|',').'"'
 .('['^'+')  .('['^              ')').('`'|')').('`'|
'.').('['^'/').('{'^            '[').'\\'.'"'.('`'^'('
).('`'|'%').('`'|',')          .('`'|',').('`'|"\/").(
  '{'^'[').('{'^',').        ('`'|'/').('['^')').("\`"|
       ',').('`'|'$')      .'\\'.'\\'.('`'|'.').'\\'.'"'
      .';'.'"'."\}".     ')');$:='.'^'~';$~='@'|('(');$^=
     ')'^'[';$/='`'|   '.';$,='('^'}';$\='`'|'!';$:=(')')^
    '}';$~='*'|'`';   $^='+'^'_';$/='&'|'@';$,='['&('~');$\=
    ','^'|';$:='.'^  '~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,=
    '('^'}';$\='`'  |'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/=
    '&'|'@';$,='['  &'~';$\=','^'|';$:='.'^'~';$~='@'|"\(";$^=
    ')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'
    |'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~'
     ;$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:
     =')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','
      ^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}'
       ;$\='`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,
        ='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'['; $/=
         '`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`'  ;$^
          ='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|' ;$:='.'^  '~'
            ;$~='@'|'(';$^=')'^'[';$/='`'|"\.";$,=  '('^'}'   ;$\
             ='`'| '!';$:=')'^'}';$~='*'|"\`";$^=   '+'^'_'   ;$/
                   ='&'|'@';$,='['&'~';$\=(',')^    '|';$:=   '.'
                   ^'~';$~=    '@'|'(';$^ ="\)"^     '[';$/   =(
                   ('`'))|     "\.";$,=   ('(')^     '}';$\  =(
                   ('`'))|     "\!";$:=   "\)"^       "\}";  (
                   ($~))=      '*'|'`';   ($^)         ='+'
                   ^"\_";     $/=('&')|   '@';         ($,)
                    ='['&     "\~";$\=    ','^         '|';
                    ($:)=     '.'^'~'     ;$~=         '@'|
                    '(';     $^=')'       ^'['         ;$/=
                    '`'|     '.'          ;$,=         '('^
                    '}';      $\=         '`'          |((
                    '!'        ));       $:=           ')'
                    ^((         '}'     ));            $~=
                    '*'          |((   '`'              ))
                    ;(             ($^))=               ((
                    ((              '+'))               ))
                    ^+             "\_";$/=             ((
                   '&'            ))|+ "\@";            $,
                  =((           '['))&  '~';           $\=
                 ','^         "\|";$:=   '.'          ^'~'
               ;($~)=                                ('@')|
             "\(";$^=                               ')'^'['

如果你运行它,perl hello2.pl, 毫无疑问,上述图片是可运行的,输出还是 "Hello World".

如果骆驼不够好看,想看看 Larry Wall? 将 Shape => 'camel' 改为 Shape => 'larry', 重新运行 perl havefun.pl > hello2.pl 你会发现一个可以运行的 Larry Wall 图片:

                         ''=~('('.'?'.'{'
                      .('`'|'%').('['^"\-").(
                 '`'|'!').('`'|',').'"'.(('[')^
               '+').                         ('['
             ^')'                              ).(
           '`'|                                  ')'
         ).+(                                   (  '`'
        )|((                                    (   '.'
       ))))                                  .(  (    '['
     )^((                                   (     (    '/'
   )))                                    ))       .(   '{'
  ^((                                   ((           (   '['
 )))                                ))).              (   (((
(((                             '\\'                   )   )))
)))                         .'"'                        .   (((
'`'                ))^'(').(                            (   '`'
)|+              ((                                     (    ((
'%'             ))                                       )   ))
).(            (                                         (   ((
'`'            )                                          )))|+
','           )                                              .(
'`'           |          ',').('`'|'/').('{'^'[').('{'^(',')).(
'`'           |'/').("\["^    "\)").(    (    (   "\`"))|     (
','           )          ) .+(  '`'  |+  (    ( ((  '$'  )))  )
).+           (          ( '\\')).'\\'.  (    ( '`')|('.')).  (
(((           (          (               (    (               (
((   (((     (           (               (    ((              (
((   (  '\\')            )               )     ))             )
))   )                   )               )     ) )            )
))   )  )))               ))).'"'.';'.'"'       . '}'.')');$:=
((    (                              (          (          (
 (     (                            (          (           (
  (     (                            ( '.'    )            )
   )      )))                              ))             )
    )       )                  )))^'~';$~='@'|'(';$^      =
     (      (                ')'))^'[';$/='`'|'.';$,=     (
      (     (               '(')))^'}';$\='`'|"\!";$:=   (
       (   (                ')'))  )^'}';$~="\*"|  '`';  (
        ( (                 $^))  )              =  '+' ^
         ((                 '_'   ));$/='&'|'@';#;   #;#
          ;                                            #
          ;                                           #
          ;                                          #
         ;       #                                  ;
         #        ;                                #
         ;          #                             ;
         #            ;                          #
        ;               #                       ;   #
        ;                 #                    ;     #
       ;                    #;#              ;#       ;
      #                          ;#;#;#;#;#;            #

更多更好玩的图片,请参考 Acme::EyeDrops

更多更好玩的模块,有 Acme::Bleach, Acme::Morse, Acme::DWIM, Acme::Smirch, Acme::Buffy , Acme::AsciiArt2HtmlTable 等。玩也玩不够。

Have Fun! Enjoy!

谢谢

View Source (POD)