Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Larry Witticisms from perl Errors

by eyepopslikeamosquito (Canon)
on Mar 14, 2004 at 06:03 UTC ( #336462=obfuscated: print w/ replies, xml ) Need Help??

This code transforms perl error messages into something more pleasing to the eye: a Larry Wall witticism!

use strict;BEGIN{$SIG{qq)__WARN__)}=sub{$..=$_[$===!$=]}}eval,$..=$@for
qq}bless("Wall","Larry"),Not("Wall","Russ");#},qq!;print Magic,counts!,
qq#use strict;\$Perl=42#,qq>goto"WALL, LARRY ONTO (OR ON?) SOMETHING">,
q~warn+Randal::Nevermind()~;s~~pop~e;$~=/^[1-7]$/?~-$&:rand$=>>$^F+!$%;
@;                                                                   =(
q~                           -F+=->*/+/*+*W*.                        ->
*/                        *.+=*+*.*/+/*+*3*/-B*+*                    ,+
1*                   +*1*\*\*\*,*2*D*2*:*c*W*,+1*\*                  \*
\*                 ]~,q~                         -Z*-                *c
*/               *:*2                              *c*               W*
,+             1*2+                                  1*/             *7
*<           */*.                                   +  =*2           */
+1          *++`                                    *   /*c          +`
*/         +1*+                                  *G  ,    I+=        *.
*2       *:*/                                   *     A    *+*       c*
2*     /*W                                    *,       ->   */*      1*
7*    7,G                                   *2           +   1*/     *7
*D   *2*                                :*/*              c   +`*    /*
3+  =*7                             *G*1                   +   1*2   *:
*/  *+*                         .*]*                        3   *7*  c*
2*  /,,                *2*:*1*/.                            +   */*  A*
7+  1*2              ->                                     *    /*  +*
,+  1*/             *3                                       *   +*  W+
1-  >*/            ,                                         *   -:  +=
*+  *.*            /                                          *W*3*  /*
.+  =*+           *                                              .-  >*
/*  3+/           *          2*+*:*W*,,I-Q,**]~,q~-F*0*D*W*7*G*3*1+  `*
/-  Z*/           +/*+*3*/*2*W    *.+=*2*    :    *   /*7*,*.     *  7*
/*  3*7           *          c *2*  .+=  *W  *    , ,I  ->*  /*7  *  :*
/*  7*,           *          / *3*7*c*2*.+=  *    W *,,I*\*]~,q~  -  ;*
1*  1*/           *          1               *    +               *  ,,
I*  G*   +,I     *           2               *    /+              1  *2
*3  *W   ,  I*,*2            *               :     *3             *  /*
+*  :*   2                   *               /     * +            *  :*
:*  7,   I  *+*               ,*.*\*/+X*7*2*3       * /+/*W*.+=*/*   .+
=*  2*    /                              *          .          *     2*
:*   :     *                            W          *           .     *7
*:    +     `                            * \*\    *            \     */
.R     *      9*T                              *]             ~      ,q
~-      Z       *                  .*-*3*/*.+=*2*/-V*+,I      *      W*
A*       /      *                .+=*+*.*/*A*7*G*,*.*3*\*     ]      ~,
q~        -     B               *+*,+1*+*1*/*A*+*,*/+/*:*W   *       .*
2*         /   *                7*,*2  *9*1*W*,*2*:*3  */*+  ,       I*
+*          W *                 ,*\*  /              -  W*D *        2*
:+           `*                 7*,   *2*/*W*3*/+=*+,=   ,=+         `-
>*            /                                            *         +*
,+            1                                           *          /,
=*            2                                          *           +*
A*           2       *                                  /            *3
,=           *        :                                *             2*
++           1          *                             3              *]
*7           *            D                          *               2*
:*          /               *                       .   +            =*
2*          /                 +                    /     +           =*
7*         1                    *2*              /-       W          *+
*:        *                          .+=*\*]~,q~            -        Z*
/,                                                                   G*
,*7+/*/*W*.*-*3*/+/*2*W*:+1->*/*0*G*.*/*W*.*/+1*7*2*3*/*c*+,G*2*/*W*.*/
*2*+*3*W*2*:*/*.*7*/+/*:*W*.*2*/,=*7*2*.*:+`*/*W*,*/,=*2*:*1*\*/.R*9*T*
]~);s;\s;;gfor@;;@;=map{$;=chop;$=*(-42+ord)-42+ord$;}$;[$~]=~/../g;#;-
print(($.=~/./sg)[@;]) #-!"#$%&'()*+,-./:;<=>?@[\]^_`!"#$%&'()*+ -- /-\
By default, one of seven witticisms is randomly displayed, though you may ask to see a specific witticism by giving a command line argument of 1-7.

Since this program depends on the precise wording of perl's error messages, you might brand it fragile in the extreme. However, I've tested it with perl 5.005, 5.6.0, 5.6.1 and 5.8.3 and found no problems so far. Here's hoping the wording of these carefully chosen perl error messages does not change in future versions of perl. :-)

Update: Put code tags in a comment so download link will work. Thanks ambrus.

Comment on Larry Witticisms from perl Errors
Download Code
Re: Larry Witticisms from perl Errors
by ambrus (Abbot) on Mar 14, 2004 at 13:01 UTC

    See the recent obfu Mandelbrot flythrough on how you can make the d/l code link work with too wide code. Thanks.

      $ perl -v

      This is perl, v5.8.0 built for i386-linux-thread-multi

      $ perl larry.pl
      Al anguedsirot.Gwhy:-)
      $ perl larry.pl
      I knowit'serd,bumapyl.:-)
      $ perl larry.pl
      Randl cwriteo-sg.Evyhp,

        I suspect the root cause of your problem, likely to be seen on Linux/Perl 5.8.0 only, is that the STDOUT file handle is UTF-8 due to your LOCALE settings. I was able to duplicate your problem in that environment. It can be fixed by setting the LANG environment variable, as shown below:

        $ perl larry.pl 1 Oh, waitsRndl.evrm $ env|grep LANG LANG=en_US.UTF-8 $ export LANG=en_US.iso885915 $ perl larry.pl 1 Oh, wait, that was Randal...nevermind...

        Alternatively, adding the following line:

        binmode(STDOUT, ":bytes");

        to the top of larry.pl also fixes.

        The root cause of this nuisance is described, as follows, in the perl 5.8.1 perldelta.

        UTF-8 On Filehandles No Longer Activated By Locale

        In Perl 5.8.0 all filehandles, including the standard filehandles, were implicitly set to be in Unicode UTF-8 if the locale settings indicated the use of UTF-8. This feature caused too many problems, so the feature was turned off and redesigned: see Core Enhancements.

        UTF-8 no longer default under UTF-8 locales

        In Perl 5.8.0 many Unicode features were introduced. One of them was found to be of more nuisance than benefit: the automagic (and silent) ``UTF-8-ification'' of filehandles, including the standard filehandles, if the user's locale settings indicated use of UTF-8.

        For example, if you had en_US.UTF-8 as your locale, your STDIN and STDOUT were automatically ``UTF-8'', in other words an implicit binmode(..., ``:utf8'') was made. This meant that trying to print, say, chr(0xff), ended up printing the bytes 0xc3 0xbf. Hardly what you had in mind unless you were aware of this feature of Perl 5.8.0. The problem is that the vast majority of people weren't: for example in RedHat releases 8 and 9 the default locale setting is UTF-8, so all RedHat users got UTF-8 filehandles, whether they wanted it or not. The pain was intensified by the Unicode implementation of Perl 5.8.0 (still) having nasty bugs, especially related to the use of s/// and tr///. (Bugs that have been fixed in 5.8.1)

        Therefore a decision was made to backtrack the feature and change it from implicit silent default to explicit conscious option. The new Perl command line option -C and its counterpart environment variable PERL_UNICODE can now be used to control how Perl and Unicode interact at interfaces like I/O and for example the command line arguments. See -C in the perlrun manpage and PERL_UNICODE in the perlrun manpage for more information.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://336462]
Approved by davido
Front-paged by arden
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-11-25 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (160 votes), past polls