My last obfuscation was impressive on first sight, but rather disappointing at the time of breaking it, until the point that I almost posted a followup apologizing for it :^). So I decided to quit doing that lame things and make something I could be proud of. And this is the result, a little program that incorporates some tens of gotchas (to me, at least) that I've found in the documentation. They're not necessarily worst practices, but I thought it would be a nice title. Sometimes titles are more difficult that the things they give name to.
It changes its behaviour from time to time (maybe), although it can be some weeks until it decides to do so. I won't be surprised if it doesn't run on win* or older Perls (5.8 required, although the script doesn't explicitly use it), indeed I had to remove a couple of features to make it work on 5.8.7. A pity. On the bright side, and definitely not a worst practice, it's strict and warnings clean -- there's a warning but it's on purpose ;^).
It's possible that it runs too slowly on your machine; if that happens, you can alter the variable $d at the top of the script. It specifies a wait time, so increasing it will make the program run slower (although it's unlikely you will need this). Setting it to zero will make it run as fast as possible. If it's slow, you could try 15 as a first approach, and see. I forgot to check for the less-than-zero condition, but it doesn't seem to break.
Oh, and it also features a small hidden text that summarizes my overall opinion about the monastery.
Usage:
-m: use medium-sized font
-s: use small font (default, and overrides -m so it's pretty useless)
-t: specify text to show instead of the default (there's another way to do this)
Example: ./pwp.pl -mt '100th post!'
(Hmm, I have a feeling I'm forgetting something...)
Update: It seems to segfault on Debian with Perl 5.8.4. I will investigate it further today. Fixed.
Update 2: Fixed termcap lookup errors.
use warnings; use strict; our $d = 20; * ,= *EUID;-JAPH=~join'\s*',('(\S+)')x4;use Getopt::Std;getopts('smt:' +,\ %;); $^]=v109 if$; {m}and!$;{s} ;%~=$ ^]eq's'?(q AoA,6,q NaN,11):reverse(14 +,q rar, 7,q pop);eval join'',map{$^[=chr qw/26 6 10 7 0/[$_]+0105;$_||($^[x=2) +;$/ = $ _==3?'use Symbol; ':'';local$ ;=chr qw/6 1 0 5 3/[$_]+77;$ a=$ _==3?'; +${*alt= *{$q=gensym}} ':'';$ S::I=$_==1?'our$X;our$ s=($X=~$q);':' ';$S::S=(qw +|qr/$q/ \$s sub{$$q;} \*alt $q|)[$_];"package $^[;${/}sub $; {our\$k=shift ;ou +r\$q$a= shift;${S::I}bless $S::S,\$k;}";}0..4;$/=( );our($ORS,%I,$I,%~,$OFS,$R +S,%a,$~ ,$l);sub I;sub v;sub ::{$5}if(open$/,'<',\$RS){while(read$/,$_,$=){$,= +$_;next unless ${*${P E R L M O N K S __ v46}{">|z<|2"^"m?;p=`"}}->();//and($ +I,$ ~)= $ ^]eq's'?($l,$.):($:,$^);$I{255-$I^0x55}=$ ~;}(*.,*^,*l,*:)=(*",*;,*= +,*b);$a { a}='$~=join"",@ ~';our@RS;sub a{local$_=(caller(fileno$/==0))[3];&u; +v36.$_} @RS=sort{sub b{local$/;@; =join' ',$ ^X=>'-e"print\''=>@_,'\';"|';eval + for<>} @~= map{pack"B8",$ _}grep!/^0{3}/&&!/^1/,map{unpack"B*",$ _}split//,de +fined$; {t}?$ ;{t}:defined$ a{&::}&&CORE::length($ a{& ::})?$a{& ::}:'';@ ~=sp +lit//,q ^Z&q>^^<0G\x01V> ^join< >=> map{y ^1-9^ --^=>s ^[0-9]^chr^e; $ _}spli +t qr^^, unpack<b{}4>,chr rand 16if!@~;$l+=ord for@ ~;return$l%2?-1:1}@RS[0177, +0377]if * K::X;b a;undef$ I;open$ I,'<'=>\3or die-OPEN1.$!;eval'"BEGIN{use Eng +lish}"' ;*^]=-+CORE'GLOBAL'undef;$a{a}='sub BEGIN{sub CORE::length{(undef,loca +l$_)=@_ ;index$_,""=>$l*$l}}';{package S;our@l;@l[split//,hex join'','b'..'d'] +=([0,-1 ],[1,fileno((bless\($ .=rand )=>--$-),$/)==0],[-1,0],[0,1]);*l=*l=sub{ +splice@ _,6,0=> splice@_,0,1;our@I=(shift,shift);()=return wantarray?():bless{ +mnm=>[@ I],mmn=>$I[1]-1,mww=>0,mmw=>$I[0]-1,mwn=>0,mwm=>shift,mnw=>shift,mmm=> +[shift, shift],},shift;sub END{$OFS->Tgoto('cm',0,0,*~);$OFS->Tputs('ve',1,*~) +;}}}our @I;b a;our@a;$ ^]=$ _ and((splice@a,($|,1,!!!$ORS)[$a++||$|],$|,0)or m +ap{$_+= $^]}@a)or@a=map{sprintf$6,$_/$_,$_,$_,$_,$_*$_}@a for qw/10 55 46 0/;@ + :=grep length,split/(??{local($ ,,$^)=((index+($.="."),"",42),substr$_,pos,1) +;$_ eq$ ^and substr$.,0,$,,""and last for@a;substr$.,0,$,,"";})/,'UE.0.ogcnoVe +sZeXMh' ;*ORS =*|;map{push@ / ,($/[-1]|| 0)-112+ord}split//,'pzw';$ _= * ^]^ 8 +.49.48x 48.48.55;@ ^[=(split//)[@ /];$^[[$ _*2+1]=$ ^[[$_*2]=$^[[$_]for revers +e 0..2; splice@I,6+@ I,0,qw/O O 0 0 @/,not do{push@I,(localtime)[8]?@ : :@ ^[} +=>'@';{ local$/;@/=($~{q LoL} *+CORE->length($~),$ ~{q yay});$,=S->l(@/,ref\$ +.,4,-1, ref\$.);$ ^]=S->l(@/,<$I>=>eval'$ORS ++;2',$/[ref\$.]-1,$/[1]);$a{a}=' +@RS=(); splice@RS,@RS,0=>int rand 2for split/'.'/,$~;';}@/=();our@OFS;$d/=1e3; +sub END {for$^[(\@/,\@OFS){select+(),((),()),(),5e-1 if$^[==\@OFS;for($.=our$I +=ref\$. ;eval'$I++if!$ ^[->[$.]'||$ORS;$. ++){$ ^=$^[==\@/?@I:-1;if(-rand 1==r +and -1) {$ .="0+(/SDLF?.2:EFLSE?:<GOSD,22'FHBS/,-#FASD#/4=FAS&9/*SDFL!< /LHA'! +gUyA3". "Bf'HAS5#/,HABV'0#81SD";BEGIN{(*b,*I,*;,*^],*RS,*a)=\('&Ut'^'h4:',@{[' +^'^'~'] },'~xyv0]_PR{.LRRjxDDO'^'<=>?~&*#7[z) ?M;%42','s',@{[0..255]},%ENV)}ou +r$,="s" ."DFH!%83SOFS*(?rOfUI`96dFGASf:'2LDHGf snujfdla&HUFA6(?lBSDJl8 SIF_1 E +'F^'4". "sAQFI,a.9SDFJHlN";warn"\n"x$~{q dad}.($ .^$,);BEGIN{sub RS{I sub{$OFS +->Tputs ('vi',1,* ~)};shift->();}(*,,*.,*EUID,*:)=(5,1,*K::X,4)}BEGIN{*~=$::{" +{>b<h/" ^"(j&s={"},*u=sub{s/.*:{2}//}}goto+v73}else{$: and do{for($ .-(@I-1).. +$ .){$^ +=$ ^[==\ @ /?-(1):1;BEGIN{sub CORE::length{return CORE::length(@_)}}d +o{print "by Hue-Bond\n"if oct ref${ P E R L M O N K }>< >or/(??{substr$ \,2+po +s,1})/} unless$ :!~/n(?{m#(?{$_})#&&sprintf q#\# %02x#,ref\$..q#@ OFS##&&$ sub +str{42} })An#"@{[defined$I&&length$I&&(sprintf$I.("6611"^"bg|a")||do{&u(q"$I/x +;print{ $OFS->Tgoto('cm',$^[->[$_][0]=>$^[->[$_][1],*~),*~}$I[$^ ]if((defined$ + ^[->[$ _]&&$ _>=ref\ $.)&&($RS[$^[ ->[$_][--$ -]/$ ~{q HoH}]?(not hex substr( +$ I{ord substr$~,int($^[->[$_][--$-]/$~{q bob})=>1},2 *$^[-> [$_][1],2)&1 <<$~ +{q mom} -1-$^[->[$_][--$-]%$ ~{q LoL}):(hex substr($I{ord substr$ ~,int($ ^[-> +[$_][-- $ -]/$~{q pop} )=>1},2*$^[->[$_][1],2) &1 <<$~{q AoA}-1-$^[ ->[$_][--$ +-]%$~{q HoH})));}select +(),(),((),()),$d;eval '"BEGIN{* CORE::GLOBAL::open=su +b{\ $_= q^?n/j_pp!|m5|meF*I,SnpI{^^q ^|!}/eJ7m3/t0W_)Z,B{./`@^^eval}}"';}or do +{$^[==\ @/and print * ^]^qq' ~,= <\cv\cz\ci-\cab29JJ\cz\c\\cpE\cheeded.\n';las +t}}last if$I==@ I-1;}}I:}BEGIN{(*l,*ORS,*^)=(split//,0552);sub I{v sub{$OFS->T +require (qw/cl cm/)};shift->();}*ORS=\('%3$*'. * 1{'p$0?'^'>e}z'}.'$.*c')}{pac +kage S; our@l;sub I{our$I=$_[our$ S=0];I:our$ww=$I->{mmm}[0]+$l[$I->{mwm}][0]; +our$wn= $I->{ mmm}[1]+$l[$I->{mwm}][1];$.=((our@I=0..3)=>'');our$l=join' els', +map{our ($j,@t,$t)=unpack"b2",$_;"if(\$I->{mwm}==@{[('ref\$.',1..$#I)[$_]]}){i +f(\$w@{ [((qw/w n/)x2)[$_]=>$::I [0],((v62)x2=>(v60)x2)[$_]]}\$I->{'m@{[((v109 +)x2 =>( v119)x2)[$_],((qw/w n/)x2)[$_]]}'}){return undef\$I->{mmm}if\$S;if(\$I +->{mnw} == 4){\$I->{'m@{[(('m')x2=>(v119)x2)[-1+$_]=>((qw/n w/)x2)[$_]]}'}@{[@ +t=split //,$ j and(0+$ t[0] ^0 +$t[1])?'--':'++'] };\$I->{mwm} = $I[-3+$_]}els +if(\$ I -> {mnw }==2){\$I->{'m@{ [(('w')x2=>(v109)x2)[- 1+$_]=>((qw/n w/)x2)[$ +_ ]]}'} @{[$ t=$ j and(0+substr($t,0,1) ^0+substr($t,1,1))?'++':'--']};\$I->{m +wm}=$I[ - 2+$ I[-3+$_] ] }else{\$ K::X=int qq'${*_{qq^>|z<|`^^ qq^m?;p=2^}}'}\ +$ S ++; goto I}}";}@I;defined eval"$l;1"and$I->{mmm}=[$ ww,$wn]or return;!!$ l +}}BEGIN {* ,=\('#d4k!k#f '^'s!f\'l$m-s') ;*;=\@ARGV;sub v{local$/=v10;$OFS=Ter +m'Cap-> Tgetent({"h=l,"^"<x>a" =>${\undef},"k#x}; "^'$p(8~d'=>$ .});shift->(); +}}while ($,-> I&&$ ^]->I){eval'package S';splice@ /,@/, 0,$,->{mmm}||<$I>;spli +ce@ OFS ,0,fileno$ /== 0=>$^]->{mmm} ||();eval'package main;';}b a;require POS +IX;$ .= new POSIX::Termios;$.->getattr;$.=$ .->getospeed;eval"$^";RS sub{$OFS- +>Tputs( 'cl',1,* ~)};package S;}else{die-OPEN2.$!}BEGIN{$RS=<<"EOF" 0004040404040404040400 004242424242424242423c000000 214 255 0018040404030404041800 003c42422418244242423c000000 215 146 0001010202040808101000 004040404040404040407e000000 133 230 0000000e101010100e0000 000000003a44444438205c423c00 201 205 0010080404040404081000 001010107c10101010120c000000 131 222 000e080808080808080e00 0018244242424242422418000000 241 154 0000000000000004040408 000000003c42023e42423e000000 134 203 00001212121212120c0000 007e404040784040404040000000 255 236 0006080808300808080600 0000000042422418244242000000 209 210 0000140814000000000000 003c424242463a02424438000000 128 147 0000000404000004040408 4040202010101008080404020200 145 246 001c040404040404040000 000000007e04081010207e000000 198 208 00001f0404040404040000 000808001808080808083e000000 254 195 00001f10101e01110e0000 004266665a5a4242424242000000 159 231 00000e04040404040e0000 0018244242427e42424242000000 227 235 0000000e121212160a021c 003c4242424242724a463c040200 205 251 00000012121212160a0000 001824242418324a444c32000000 223 140 000000001f001f00000000 0000000022222a2a2a2a14000000 151 221 00001212121e1212120000 0042426262524a46464242000000 226 228 001010141a121212120000 000e040404040404444438000000 194 224 00001c12121c1010100000 0000000000000000000000007e00 250 245 000a0a0a00000000000000 003c424204080808000808000000 136 149 0000000c020e12160a0000 007f080808080808080808000000 203 254 0010101214181412110000 000000003c42427e40423c000000 193 207 0000001115151f0a0a0000 0204080810101010100808040200 221 130 0000000019260000000000 001c2040405c624242423c000000 212 156 00000e0404040404040438 1e10101010101010101010101e00 224 241 00000e12202022120e0000 000000005c62424242625c404000 237 218 0000000000000000000000 2010080804040404040808102000 213 131 0000111b1b151511110000 3c04040404040404040404043c00 231 247 000000121212120c0c0000 000000003a46424242463a020200 220 219 00000c0c12121e12120000 001414143e14143e141414000000 235 137 00000c12212121120c0603 007c424242427c48444242000000 251 248 00001c222e2a2f201e0000 000000000000000000081c080000 234 132 001010141a1212121c0000 007e02040808102020407e000000 200 240 0000000204080402000000 003c424240300c0242423c000000 150 249 00000e11111111110e0000 003c424240404e4242463a000000 154 237 0000001a15151515150000 0000000000000000000000000000 199 213 0000000000000000003f00 0000000000003e00000000000000 245 135 00001010101010101e0000 3008080808080408080808083000 230 215 0000000808000008080000 000000081c080000081c08000000 144 144 00001c12121c12121c0000 000000005c624240404040000000 232 216 000004040a0a1111000000 1824420000000000000000000000 244 244 000000110a04040a110000 004040405c62424242625c000000 210 200 00000e11010608101f0000 000818280808080808083e000000 152 155 0004001c04040404040438 007e020404080810102020000000 192 157 001c040404040404041c00 0000020408102010080402000000 247 150 0000000000000008080000 000000003c42424242423c000000 132 197 00001e10101c1010100000 000202023a46424242463a000000 236 206 00000000001f0000000000 0000000000000000000000000000 135 138 0000112a14040a15220000 0202040408080810102020404000 143 133 0000040c14040404040000 00324a4c3808101c32524c000000 155 143 0000121a1a161612120000 00000000342a2a2a2a2a22000000 228 199 0000080808080008080000 007e40407c42020242423c000000 139 159 0000001008040810000000 000000082a1c081c2a0800000000 148 128 0000081e08080808060000 00040c14142424447e0404000000 222 158 00081e28281c0a0a3c0800 1008040000000000000000000000 142 202 00000e11110e11110e0000 0022222214140808080808000000 146 243 00000c120c0d12120d0000 0000201008040204081020000000 140 148 0000111515151f0a0a0000 000000003c42404040423c000000 253 201 00000e11010601110e0000 003e08080808080808083e000000 153 227 0000141436143614140000 0000000018180000180808100000 137 145 0000001e020408101e0000 0042424242242424181818000000 208 252 0000060a0a121f02020000 00083c4a4a281c0a4a4a3c080000 158 142 000000141a121212120000 0000000022222214140808000000 196 220 00000e11110f01110e0000 000000005c624242424242000000 147 196 000011110a040404040000 003c42424242424242423c000000 243 229 00001c12121c1412120000 0000000042424242463a02423c00 248 211 0000001212120c0c081010 001808080808080808083e000000 211 198 0000111214181412110000 0008080808080808000808000000 225 139 00000e1101060004040000 20524a0400000000000000000000 149 212 0000000000000000000000 000c1210107c1010101010000000 138 204 0000000e101806021c0000 0000000000000000001808081000 217 134 000012120c0c0c12120000 004040405c624242424242000000 242 194 0804000000000000000000 007e40404078404040407e000000 202 239 00001e02040c08101e0000 003c42420204040810207e000000 240 152 0007081e08080808080000 000000007e00007e000000000000 204 151 0000000c121212120c0000 003c42424040404042423c000000 197 233 0000000c121e10100e0000 0078444242424242424478000000 207 238 0002040808080808040200 002222222222222a2a2a14000000 130 253 00001f0102040408080000 007e0204081c020242423c000000 157 153 00000e12202020100e0000 0000000808083e08080800000000 233 129 0000000b0d080808080000 0078444244784442424478000000 216 232 00001e10101c10101e0000 000000003c42201804423c000000 239 217 0000121212120c0c0c0000 000000004242424242463a000000 252 223 0002020e121212160a0000 0042444850605048444242000000 206 225 00001c12111111121c0000 0002020006020202020222221c00 238 192 0004040400000000000000 1414141400000000000000000000 141 136 0004001c04040404040000 0608080808081008080808080600 195 209 000000141a1212121c1010 0808080808080808080808080800 218 214 00000004041f0404000000 007c424242427c40404040000000 129 250 00000e10100c02021c0000 0042422424181824244242000000 249 242 0010100808040202010100 0808080800000000000000000000 246 141 00000e11101e11110e0000 0040404044485070484442000000 156 193 00000c12212121120c0000 00424242427e4242424242000000 229 226 0000000e121212160a0202 001c224e525252524e201e000000 219 234 EOF }
--
David Serrano
In reply to Perl Worst Practices by Hue-Bond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |