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
YAPC::EU::2013 reg.ru Go Perl golf contest
1 direct reply — Read more / Contribute
by nobull
on Aug 13, 2013 at 10:35
    reg.ru sponsors of YAPC::EU::2013 set this challenge based on the game of Go:
    1. Problems are given for a Go training board with the size of 9×9.
    2. Black moves first.
    3. There are no stones already captured on the board.

    Input: nine lines which represent the playing board are sent to STDIN. Lines consist of spaces (for vacant points on the board), "w" symbols (for white stones) and "b" symbols (black stones) and end with the new line symbol ("\n").

    Output: сoordinates (row and column numbers separated with a space, counted from one) of points, a move to which results in the capture of white stones. Results must be sent to STDOUT, one point per line. Results must contain all the possible moves on the board which would lead to the capture of white stones. Points are to be output in the order of their position on the board (left to right, top to bottom).

    This is my first attempt at Perl-golf and (because BooK wasn't here this year) I actually won with 205 characters. (Woo hoo!)

    #!perl $b=++$/x11 .<>;for$i(9..99){if(($x=$b)=~s/^(.{$i}) /$1x/s){while($x=~/ +w/g){$_="$`W$'";1while s/w((?<=W.{10})|(?<=W.)|(?=.{9}W|W))/W/s;/W((?<= .{10})|(?<= .)|(?=.{9 +} | ))/s||$i=~/./+(print"$& $'\n")+last}}}
    Or with comments and whitespace
    #!perl $b = ++$/ x 11 . <>; # $/='1' (not prese +nt in input). Slurp STDIN. # Prepend '11111111 +111' so top left is at 11. # Leave the "\n" in + to act as border and make # rows 10 so linear + pos is also row/col. for $i (9..99) { # Scan all possible + cells (including border). if( ($x=$b) =~ s/^(.{$i}) /$1x/s ) { # If cell is ' ' pl +ace 'x' in a copy of board. while( $x=~/w/g ) { # Consider each 'w' + in turn and $_ = "$`W$'"; # copy board high +ighing that 'w' as 'W'. 1 while # Until you run out +, s/w((?<=W.{10})|(?<=W.)|(?=.{9}W|W))/W/s; # highlight a nei +ghbouring 'w'. /W((?<= .{10})|(?<= .)|(?=.{9} | ))/s # Find a 'W' neighb +ouring a ' '. || # If there is no su +ch peg we have captured. $i=~/./ + # Split row number +out of cell number. (print"$& $'\n") + # Print row and col +unm. last # Advance to next p +ossible cell. } } }

    Improvements from the Monks welcome.

Hello World!
No replies — Read more | Post response
by Anonymous Monk
on Aug 11, 2013 at 14:54
    use integer; for(104,4294967293,4294967271,32,-29, -hex("2F"),87,ord(8)-(8)*(8),"7" & ~(9%5),hex((F x 7).chr(oct(unpack( chr(6x2).2**5,pack("N",5))))),-8, -90){$a+=$_;$chr=5;print(chr($a));}
Dilbert don't warn!
4 direct replies — Read more / Contribute
by tobyink
on Jul 08, 2013 at 05:38

    This is an interesting feature of Perl that's recently come up on p5p as a candidate for removal. Not obfuscated, but obscure certainly.

    #!/usr/bin/env perl use warnings; "pointy haired boss"; "dilbert"; "dogbert"; "wally";

    Outputs:

    Useless use of a constant ("pointy haired boss") in void context at sc +ratch.pl line 5. Useless use of a constant ("dogbert") in void context at scratch.pl li +ne 7. Useless use of a constant ("wally") in void context at scratch.pl line + 8.

    What? Why doesn't "dilbert" generate a warning?

    Turns out that before pod became the standard for Perl documentation, people used to embed strings of nroff in Perl scripts. Any strings that begin with "di", "ds" or "ig" look enough like bits of nroff to be exempt from the void warning.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
A bit of fun with pack/unpack
2 direct replies — Read more / Contribute
by FloydATC
on Jun 28, 2013 at 04:28

    My first, humble attempt at writing (intentionally) obfuscated code:

    use strict; use warnings; @==map{unpack('B24',pack('V',$_))}(12580855,16776063,103792,10764419,8 +561235,856483,1974885); foreach$"($[..23){$:=$[;foreach$\($[..6){$:.=substr($=[$\],$",!$[)}pri +nt(pack('B8',$:))}print$/;
    -- FloydATC

    Time flies when you don't know what you're doing

Lightly toasted JAPH
No replies — Read more | Post response
by rjt
on Jun 27, 2013 at 07:59

    This JAPH will hopefully give you brief pause, in a meditative sort of way. Stop and smell the roses. --<--<@

    If you like cracking ciphers, take a look at the spoiler tag below first, before you take a hard look at the JAPH code.

    sub _{q{%-2L9^!F.Q&4B5B+/7C*3C6 1B' (C,08 # $) "}}sub O{chr$.}$. =($|||=!$!^$.)^33,;print@@if map{$%=-33+ord substr&_,$_;$->$%?$. ++:$%<1<<2<<3?$@[$%]=O:($.+=$%-31)}0..length _

    Cipher:

Glob in the JAPH
1 direct reply — Read more / Contribute
by Eily
on Jun 17, 2013 at 19:00

    This morning, the weather was quite warm and sunny, so I decided to take my bike to go to work. I didn't bother looking what it would be like in the evening. So I ended up in front of my computer, waiting for the rain to stop falling long enough for me to come back home, because I hadn't thought about taking a jacket. To pass the time, I made this:

    ($R,$B)=(q, another,,q( Perl hacker,),$a=Just);$, =$V;m;(.)\(\)?;;*V=$::{$1};$\=$V;BEGIN{$|;$_=\$:: {b};m;(.)\(\)?;;*V=$::{$1}}print @$_ for [$a,$b],

    My favorite JAPHs are those where the printed text isn't already obvious in the code. So I could have added some encryption or something to this one, but I thought I should rather stick to one main concept (concept I stumbled upon by accident) and shape (quite literally) this script around it. I still used some other obfuscations here and there to prevent the whole script from being too obvious, and to make it fit in a rectangle.

    It does not run under strict, and warnings may make it easier to understand.

My JAPH
1 direct reply — Read more / Contribute
by varnie
on Jun 17, 2013 at 12:23
    Hi there. Here's my JAPH:
    #!/usr/bin/perl use warnings; use strict; my$k='my$i=0; foreach my $v (-4,26,10,-4, -104,-56, -61 ,-79,-94,-127 ,-152,-162, - 268,-245,-250 ,-264,-298, - 403,-361,-399 ,-429,-454, - 494,-516){$_[ $i++]+= $v; } join"",map{chr }@_;';foreach( reverse(12..35) ){$k="sub{$k}-> (\@_, int map{( int)x\$_}(1..$_ ))"}print eval$k
    Shrinked version:
    #!/usr/bin/perl use strict; use warnings; my$k='my$i=0;foreach my$v(-4,26,10,-4,-104,-56,-61,-79,-94,-127,-152,- +162,-268, -245,-250,-264,-298,-403,-361,-399,-429,-454,-494,-516){$_[$i++]+=$v}j +oin"",map {chr}@_;';foreach (reverse (12..35)){$k="sub{$k}->(\@_,int map{(int)x\ +$_}(1..$_ ))"}print eval $k;
Pumping JAPH
1 direct reply — Read more / Contribute
by choroba
on May 13, 2013 at 11:03
    My first JAPH. Works under strict and warnings, too.
    $|--;for($/=1/10;$/<=1/2;$/+=50e-7){$\=qq/J,\r/; substr$\,$/*length$\,$/-$/,$_,for split/(.{2})/, q/ursetk caanho tlhreerP /;print'';}warn qq/\n/;

    Update: Retitled.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Length of array in hash of arrays
1 direct reply — Read more / Contribute
by ambrus
on May 09, 2013 at 09:57

    Question

    I have a hash of arrays like this:

    my %g = ( k => [8, 2, 10, 2, 1, 3], l => [10, 7, 9, 0, 1] );
    I know I can access the first element in one of the arrays like $g{k}[0]. But how do I get the length of that array?

    Answer

    Just try using random sigils, some combination is bound to work. The following script eases this task: it quickly runs all combinations of random sigils and prints the code that gives the right answer.

    use 5.014; no warnings; # some non-sensical combination of sigils would give warn +ings use strict; # we want answers without symbolic references my %g = ( k => [8, 2, 10, 2, 1, 3], l => [10, 7, 9, 0, 1] ); sub sigil_combination { sprintf("%X", $_[0]) =~ y/0-9A-F/$@#%*~^\->(){}.,;/r; } for my $n0 (1..1e5) { my $c = "length " . sigil_combination($n0) . "g{k}"; if (6 == eval $c) { say "$c"; } } __END__
Fibonacci Sequence
2 direct replies — Read more / Contribute
by skunix
on Feb 27, 2013 at 00:59
    $~=$^=1;s//1 1 /;_:$~^=$^ ^=$~^=$^;$_.=($~=$~+$^." ");($~<99)?goto _:print

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":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.