http://www.perlmonks.org?node_id=1597

Got some code which would take a Perl grand master to understand without running it? Post it in this section so we can stare at it in awe.

Word of warning, though: Don't be too cocky with your post — almost inevitably someone will post a reply that does the exact same thing in even fewer characters!

New Less than Readable Code
A twisty little maze of ampersands, all different
1 direct reply — Read more / Contribute
by haj
on Jun 08, 2021 at 18:54
    The following code prints a 0, a 1, a 2, and an empty line. But which is which?
    use 5.020; sub one { 1 } sub two { 2 } say one&two ; say &one&two ; say &one&&&two ; say &&&one&&&two;

    It is not that difficult to figure out, it was a accidental discovery while messing around with syntax highlighting. For the friends of JAPH, here's one with five consecutive ampersands:

    use 5.020; sub s { say }; $_ = 'Jusst another Perl hacker'; s&s&&&&&s
reftype obfu -- oneliner
1 direct reply — Read more / Contribute
by Discipulus
on Apr 22, 2021 at 16:06
    perl -MScalar::Util=reftype -e "$}=qr/=.=/,print+(join$\,map{chr(ord($_)-8)}((reftype$})=~/./g))=~s/$}/A/r"

    or

    perl  -e "$}=qr/=.=/,print+(join$\,map{chr(ord($_)-8)}((uc ref$})=~/./g))=~s/$}/A/r"

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
The Backslash Challenge
4 direct replies — Read more / Contribute
by choroba
on Mar 24, 2021 at 16:12
    To return the character that's used as the delimiter in a quote-like operator, you can use a backslash.
    '/' eq q/\// or die "Failed";

    Your task is to return a backslash using a backslash as the delimiter. Use qq\\ for level easy, use q\\ for level guru.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
The IP address I'd like to own -- oneliner
1 direct reply — Read more / Contribute
by Discipulus
on Mar 16, 2021 at 03:13



    perl -MSocket -le "print eval inet_ntoa(inet_aton([gethostbyaddr(inet_aton('74.65.80.72'),AF_INET)]->[0]))"


    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Emoji can be hard to see on the command line
1 direct reply — Read more / Contribute
by kcott
on Feb 06, 2021 at 14:16

    ++eyepopslikeamosquito's post (a reply in an unrelated SoPW thread) inspired me to look at Acme::EyeDrops.

    After playing around with that module for a bit, I realised that some of the obfucation code images looked a bit like blown-up versions of emoji. It then occurred to me that not only could I get large, very easy to see, representations of emoji, but I could also use those images to get back the original Unicode® emoji character. Here's a couple of examples.

    Firstly, a very straightforward one that only required one shape.

    $ perl -C -e 'print "\x{1f56f}\n"'
    🕯
    
    $ cat candle.txt ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( '' ) ) ))) ) ) ) ) ) ))))) ) =~("\(". ( ( '?')).'{' . ( ( '`')|'%') .('['^ ( '-') ) . ( '`'|'!') . ('`'|"\,"). '"'.('['^"\.").( '['^'(').('`'|('%')).( '{'^'[').('`'|'/').(('[')^ '+').('`'|'%').('`'|'.').( '{'^'[').('['^'*').("\["^ ',').'\\'.'{'.':'.(('[')^ '(').('['^'/').('`'|'$').( '{'^'[').':'.('`'|'%').('`' |'.').('`'|'#').('`'|"\/").( '`'|'$').('`'|')').(('`')| '.').('`'|"'").'('.(('{')^ '.').('{'^'/').('`'^'&' ).'-'.(':'&'=').')'.''. '\\'.'}'.';'.('!'^'+'). ('['^'+').('['^(')')).( '`'|')').('`'|'.').('[' ^'/').('{'^'[').('\\'). '"'.'\\'.'\\'.('['^'#') .'\\'.'{'.('^'^('`'|'/' )).('`'|'&').('^'^('`'| ( '+'))).('^'^('`'|'(')). ('`'|'&') .'\\'.'}'.'\\'.('\\').( ( ( '`'))|('.')). '\\'.'"'.';'.('!'^'+'). ( '"')."\}". ')');$:='.'^"\~"; $~='@'|'(';$^=')'^"\["; $/='`'|'.';$,='(' ^+ '}';$\='`'|'!';$:=')'^'}';$~='*'|'`' ;$^='+'^'_';$/="\&"| (( '@'));$,='['&'~';$\=','^'|';$:='.'^'~';$~='@'|'('; ($^) =')'^'[';$/='`'|"\."; $, = ( ( ( '(')))^"\}"; $\='`'|'!';$:= ')'^'}';$~='*'|'`' ;$^='+'^'_';$/='&' |(( '@' ));
    $ perl -Mre=eval candle.txt
    🕯
    

    And a tad more complicated one that required two shapes.

    $ perl -C -e 'print "\x{1f459}\n"'
    👙
    
    $ cat bikini.txt ''=~('('. '?'.'{'.( (( (( (( (( (( (( (( (( (( (( ( (( (( (( (( (( (( (( (( (( (( (( (( ( (( (( (( (( (( (( ( ( (( ( (( (( ( (( (( (( ( (( (( (( ( ( (( (( ( (( (( (( (( ( (( ( (( (( ( (( (( (( (( '`' )))) ) )) )))) ))))) )) )) )))))) ))))))) )) )) ))))))) ))))))))) )) )) ))))))))) ))))))))))))) ))))))))))))) ))))))))))))) ))))))))|'%'). ('['^'-').('`'| '!').('`'|"\,"). '"'.('['^'.').('['^ '(').('`'|('%')).( '{'^'[').('`'|"\/").( '['^'+').('`'|('%')).( '`'|'.').('{'^'[').("\["^ '*').('['^',').'\\'.('{'). ':'.('['^'(').('['^('/')).( '`'|'$').('{'^'[').':'.("\`"| '%').('`'|'.').('`'|'#').('`'|'/').('`'|'$').('`'|')').('`' |'.').('`'|"'").'('.('{'^'.').('{'^'/').('`'^'&').('-').( ':'&'=').')'.'\\'.'}'.';'.('!'^'+').('['^'+').('['^')') .('`'|')').('`'|'.').( '['^'/').('{'^('[')). '\\'.'"'.('\\'). '\\'.('['^'#'). '\\'.'{'. ('^'^('`' |'/')).('`'|'&').('^'^('`'|'*')).('^'^('`'|'+')).((';')& '=').'\\'.'}'.'\\'.'\\'.('`'|'.').'\\'.'"'.';'.('!'^'+') .'"'.'}'.')');$:='.'^'~';$~='@'|'(';$^=')'^'[';$/=('`')| '.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^="\+"^ '_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~';$~="\@"| '(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:="\)"^ '}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\ =','^'|';$:='.'^'~';$~='@'|'(';$^=')'^'[';$/ ='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^ '}';$~='*'|'`';$^='+'^'_';$/="\&"| '@';$,='['&'~';$\=','^"\|";$:= '.'^'~';$~='@'|'(';$^=')'^ '[';$/='`'|'.';$,=('(')^ '}';$\='`'|'!';$:=')'^ '}';$~='*'|('`');$^= '+'^'_';$/='&'|'@' ;$,='['&"\~";$\= ','^'|';$:='.' ^'~';$~=('@')| '(';$^="\)"^ '[';$/="\`";
    $ perl -Mre=eval bikini.txt
    👙
    

    In case you were wondering why one is coloured and the other isn't: CANDLE (U+1F56F) does not have the Emoji_Presentation property, so it defaults to text style; BIKINI (U+1F459) does have that property, so it defaults to emoji style. If this interests you, see "Text vs Emoji, v13.1" for specific information, and "Unicode® Emoji Charts v13.1" for links to more general discussions.

    Finally, in case it wasn't obvious, this was intended as a bit of tongue-in-cheek fun. My eyesight is not so poor that I need foot-high images to tell one emoji from another. 👁️ 😕 👓 😃

    — Ken

Making a point on LinkedIn about Perl;
No replies — Read more | Post response
by ait
on Jan 11, 2021 at 14:57
    eval eval '"'. ('['^"\+").( ('[')^ ')').('`'|')'). ('`'|'.'). ('['^'/').('{'^'[' ).'\\'.'"' .('{'^ '+').('`'|'%').('['^ ')').('`'|',').('{'^ '[').('`'|')').(('[')^ '(').('{'^'[').("\{"^ '/').('`'|'(').('`'|'%' ).('{'^'[').(('{')^ '(').('`'|'(').('`'|')').( '['^'/')."\!". '\\'.'\\'.('`'|'.').'\\'.'"'. ';'.('!'^'+'). '"';$:='.'^'~';$~='@'|'(';$^=')' ^'[';$/='`'|'.' ;$,='('^'}';$\='`'|'!';$:=')'^"\}"; $~='*'|"\`";$^= '+'^'_';$/='&'|'@';$,='['&'~';$\="\,"^ '|';$:='.'^'~'; $~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^ '}';$\='`'|'!' ;$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'| '@';$,='['&'~' ;$\=','^'|';$:='.'^'~';$~='@'|'(';$^="\)"^ '[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`' ;$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|';$:='.'^'~';$~= '@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\='`'|'!';$:=')' ^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='['&'~';$\=','^'|' ;$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$,='('^'}';$\= '`'|'!';$:=')'^'}';$~='*'|'`';$^='+'^'_';$/='&'|'@';$,='[' &'~';$\=','^'|';$:='.'^'~';$~='@'|'(';$^=')'^"\[";$/= '`' |'.';$,='('^'}';$\='`'|'!';$:=')'^'}';$~='*'|'`';$^ =(( '+'))^'_';$/='&'|'@';$,='['&'~';$\=(',')^ "\|";$:= '.' ^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.'; $,='('^ '}' ;($\) ='`'|'!';$:=')'^'}';$~='*'|'`' ;$^='+' ^(( '_'));$/='&'|'@';$,='['&"\~"; $\=','^ '|' ;$:='.'^ '~';$~='@' |"\("; $^=')' ^+ '[';$/= '`'|'.'; $,='(' ^"\}"; $\ =('`')| "\!";$:= "\)"^ "\}"; ( ($~))= '*'|'`'; ($^) ='+' ^"\_"; $/=('&')| '@'; ($,) ='['& "\~";$\= ','^ '|'; ($:)= '.'^'~' ;$~= '@'| '('; $^=')' ^'[' ;$/= '`'| '.' ;$,= '('^ '}'; $\= '`' |(( '!' )); $:= ')' ^(( '}' )); $~= '*' |(( '`' )) ;( ($^))= (( (( '+')) )) ^+ "\_";$/= (( '&' ))|+ "\@"; $, =(( '['))& '~'; $\= ','^ "\|";$:= '.' ^'~' ;($~)= ('@')| "\(";$^= ')'^'['

    To run this program, just copy and paste the code into a text file, for example: pits.pl.
    Then just run it like this:

    perl pits.pl
Cumulative Guessing JAPH
3 direct replies — Read more / Contribute
by kschwab
on Jan 06, 2021 at 19:31

    May take a while on an old PC.

    Also see Progressive JAPH by Athanasius.

    $|++,$a=$b='Ktru!`onuids!Qdsm!i`bjds-',$==length$b,$b^="\01"x$=, @_=map{chr}(32..126);while($=>(($a^$b)=~tr/\x0//)){for(sort{rand >.5}1..$=){substr($a,$_-$|,1)ne(substr($b,$_-1,1))and substr($a, $_-$|,1)=@_[rand@_],print"\r",$a;select($,,$,,$,,.001)}};print$/
Self-referential QR code / JAPH
No replies — Read more | Post response
by davido
on May 31, 2020 at 23:40

    A proper JAPH this is not. And there's not really any obfu here but I thought this was a fun abuse of QR codes and Perl:

    use Term::QRCode;for(DATA){shift&&do{seek$_,0,undef$/};print Term::QRC +ode->new->plot(<$_>)} __DATA__ Just another Perl hacker,

    You'll need to install Term::QRCode, which will fail unless you have libqrencode-dev installed (Debian, Ubuntu).

    Usage:

    $ perl qrjaph self # Generate a QR that contains this script as its en +coded text. $ perl qrjaph # Generate a QR that contains just the text Just an +other Perl hacker,

    The output isn't something I can copy/paste here, so you'll either have to give it a try or take my word for it. ;) This constitutes a violation of several of the rules of JAPH scripts: It relies on several non-Perl-core libraries. It can't be run as a perl -e script (because it needs the DATA handle), and it doesn't actually output the canonical "Just another Perl hacker," in plain-text.


    Dave

my personal Easter Egg
1 direct reply — Read more / Contribute
by Discipulus
on Apr 12, 2020 at 08:44
    next time: 2093

    # easter # egg to monks use LWP::UserAgent; $ss1='0720971121121'. '210320690971151161011'. '1403211611103212111111' . '703209710810803301004'.'6'. '046'; $ss2 ='0971101000321' . '040971121121210320981051' . '1'. '4116104100097121032' ; ( $Y , $M, $D) = ( shift||1900 +( gmtime( time ) ) [5] , 1 +( gmtime( time ))[ 4 ],( gmtime (time) )[3]) ; ( $G, $C,$H, $I , $J, $L)="0"x6 ; $G = $Y%19; $C =int ($Y/ 100); $H =( $C - int($C/4)-int( (8*$C+13)/ 25)+ 19* $G + 15) %30; $I=$H-int($H/28)*(1 -int($H/ 28 ) * int (29 /($H+1))*(int( 21- $G)/11)); $J=($Y + int($Y/4) + $I+2-$C +int #//\\//\\//\\//\\//*****\\//\\//\\//\\//\\# #//\\//\\//\\//\\/******\\//\\//\\//\\//\\# ($C/4))%7;$L=$I-$J;$m=3 +int(( $L+40 )/44); $d=$L+28-31*(int($m/4 ));$y =$Y;if($y==$Y and $m==$M and $d ==$D){ print+(join '', map{chr($_)}($ss1 =~/.../g)),( $m == 4 and $d == 12 ? + ( join '', map { chr ($_ ) }( $ss2 =~ /.../g ) ): 'by ') ,LWP::UserAgent->new->get('htt'. 'p://www.perlmonks.org/index'. '.pl?no'.'de_id=174111')-> title(),$/}

    PS code inspired (read: stolen) by this

    PPS no spoiler replies please ;)

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Twenty years of perlmonks!! Happy birthday to you all!!
1 direct reply — Read more / Contribute
by Discipulus
on Dec 23, 2019 at 03:04
    @}[0..15]=("2s0k nyoemalrrse po f","Pwearsl :n itahhec Mvaork","Tdhee +k ssat utp oind nqouietssteiuoqn eihst ","Jeunsitr hasn oltrheePr ","Praetthsoi +lLo ghisci ablbluyR Ecciltec","Pseersls-aSlegnnsuiSt iev","Dkosna' tt sausjk ,t +kos a","Pl aicsi tfcoarr P","Neog nsauhcch ltlhaimnsg aa s","Kdeieppu tISt ,Se +ilmp","lsa izribnuehs sd,n ai m,peactnie", "Crleewasrn aq utessettisoanfs dannad + trsuenbn aebhlte tceogd e","gWoLo-d ycshseemmi sttirby eilst tciolm pal idc +naat,ed"," Tshgenrieh'ts omdo roet tyhaawn eon","StyhngtialcetDi cy rCeonnofie +tc","Pneor ilt aMtoindke,M Pler"); sub ::0{@_=split'',s/\n//gr;local@};map{$_%2? +push@},$_[ $_]:unshift@},$_[$_]}reverse 0..$#_;@}}Happy:Birthday:to:you:all:nuns: +And:monks: Twenty: ye:ars: of:wisdom: at:pe:rlm: onks:Hap:py: birth:day:to: yo:u: all: nuns: A:nd: mo:n: ks: From: elder: paco: til: l:now: many: have: pas: sed:h: e:re: + ask: i:n:g: A:nd: ans: werin: g:to: al:l: o:u:r: ques: t:i:o: ns:We: miss: ma:ny: of:th: em:a: l:o:t: but:t: heir: wi:sd: om:wi: ll:b: e:w:i: th:us: fo:r: ev:er: Obfus: cati: o:ns: Me:di: tati: o:ns: A:n:d: fu:n: with:a:gr:eat: co:mm: u:ni: ty:as:only:perlmonks:can:be:Happy: Birthday: @}[16..25]=("gcoi taehreeahd .a. .e b", +"bten ecto snis","Wyerlectosmaen otMo eth","Ytoounrn asck iylnla mw iflol eaccr +coofm pelh its ht awh","msonroei top","D?oe ryao us eklnboawi rwahve rreu oy","Xr +Pe bimsu n j uas t","Whec udmo n.'.t. ebriethe sneeiwb","Tghniinlkp uaobCo uets +oLo","P?rs oib lteim sk?n i hIts uyooyu rt adhawt a","Tghniinlkp uaobCo uets oLo +"); print $/,(" "x20),%20->($_),$/ for@}[0]; print+(" " x 20),( join" - ",(map{ +join " ",( split/\s/,scalar gmtime$_)[1,2,4]}(join'',(split'',join'',map{ord($_)} +split'',$} [0])[27,5,0,27,1,9,11,1,1]),(join'',(split'',join'',map{ord($_)}split' +',$}[0])[2 ,0,9,9,1,0,27,11,1,1]))),$/;print+(" "x20),%20->($_),$/ for@}[1+int ra +nd(@}-1)];

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Set the new obfuscation standard
Title:
code@?#!:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":