Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
No such thing as a small change.
 
PerlMonks

Obfuscated code

 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

( #1597=superdoc: print w/ replies, xml ) Need Help??

Got some code which would take a Perl grand master to understand without running it? Put it here 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
Decimal Gray Code in 31 chars
on Jan 18, 2010 at 17:14
2 direct replies by Oromis92
    print(($_^$_>>1).$/)for(0..pop)

    simplest as possible

Yuletide Greetings!
on Dec 24, 2009 at 17:04
0 direct replies by je44ery
    $t = int rand(14) + 6; $t = $t % 2 ? $t + 1 : $t; for $l (1..$t) { print ' ' x ((int(($t + 1) / 2 )) + 1) . "*\n" if $l == 1; print ' ' x (int(($t + 1) / 2 )) . '/' . (int rand(2) ? "#" : '&') . "\\\n" if $l == 2 ; print ' ' x ((($t + 1) - ($l + ($l % 2 ? 0 : 1))) / 2) . '/' . (int rand(2) ? "#" : '&') x ($l + ($l % 2 ? 0 : 1)) . "\\\n" if $l >= 3 ; } print '^' x ($t + 3) . "\n"; print ' ' x ($t / 2) . '|H|' . "\n";
Xmas Msg (just for linux)
on Dec 23, 2009 at 14:40
0 direct replies by smokemachine
    perl -e'*MERRY=*\;*XMAS=*/;' -F: -nae'$,=join q,,,map{chr$_+@{[(1)x un +pack q C\CC,q q \q \q q]}}q 1007769828289001 =~/.{2}/g;BEGIN{*SANTA = + *ARGV}$MERRY=$XMAS;print$F[0],join q,,,map{chr}q;0991041141051151161 +09097115;=~/(.{3})/g;BEGIN{push@SANTA,join q,,,map{chr}q 304710111609 +90471120971151151191003 =~/(.{3})/g}'
Functional Composition
on Dec 17, 2009 at 15:41
2 direct replies by billh

    This isn't really obfuscation, it's even vaguely useful, but see if you can figure out what Pipes.pm must be doing, given that this prints o-l-l-e-H

    use strict; use warnings; use Pipes; print "hello" | fn { ucfirst($_[0]) } | fn { [ split('', $_[0]) ] } | fn { [ reverse(@{$_[0]}) ] } | fn { join('-', @{$_[0]}) } | fn { $_[0] . "\n" };
    Bill H
    perl -e 'print sub { "Hello @{[shift->()]}!\n" }->(sub{"World"})'
Doing it with command line switches
on Dec 10, 2009 at 08:43
3 direct replies by JavaFan
    On the chatterbox, PhilHibbs asked Does anyone know how to make ls produce a comma-separated list, or have a perl one-liner to do it?

    Here's a solution that does it all with command line switches:

    ls -1|perl -054lp012e1
    I leave it as an exercise to the reader to figure out how it works.
JAPH again
on Nov 11, 2009 at 09:18
0 direct replies by mtve

    Few variants of no-digits obfu:

    #!perl -l print map chr oct oct oct oct hex,debf,fbbcf,hex hex eaff,adfff; print map chr oct oct oct oct oct hex,abadf,hex cd,hex ec,ffaef; print map chr oct oct oct hex,hex hex oct hex bfd,dbbf,fbbbd,ea;

    Update: finally, more fun

    print chr oct oct oct hex for qw acfed ccf debf cdefa
first cut at JAPHs
on Oct 24, 2009 at 16:17
0 direct replies by jakobi
    perl -MPOSIX -e 'sub _{($.,$/)=@_;eval"\$\\.=sprintf\"\%s\",\"".(grep{s/\S/do{(ord($&)<42+4*2**0.42)?chr((42\/3+1)<<3):$&}/ge,42}grep{s%(?!$)%do{$//=2;"\\\/".(($/=~s/\.\S*//)?ceil sqrt 42:int sqrt 42)}%ge,42}sprintf("%x",$.))[0]." \""};@_=(42292,14,32458834,72,58668,5,8469330,32);while(@_){_@_;@_=@_[2..$#_]};print'|tr UNIX~ REWOP|cat -vet

    The vet's first diagnosis: The poor kitten seems to be erudite, but it should probably try a diet of less theory, and instead actively some play rounds of golf. Cautious use of source filtering may also provide support in refactoring into a lean beast. @_@

Format quine (slightly obfu)
on Oct 15, 2009 at 18:01
1 direct reply by bv

    Couldn't figure out how to get the #! to work, but it's not really necessary. Uses the open 0 trick, so save it to a file before running

    use strict ;my@f; use warnings ; open 0;$/= \11;my $i= 0; while ( <0>){chop; push@{$f [ $i]},$_;$i =($i+1)%3} close 0;$~ ="it"; my( $l,$m,$r)= map{$f[$_] }(0 .. 2); for(0..$#{ $l}){$m->[ $_]||= ''; $r-> [$_ ] ||=''; #$l }){ $m ->[ format it= @<<<<<<<<< @<<<<<<<<< @<<<<<<<<< $l-> [$_], $m-> [$_], $r-> [$_], . write;}

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Fibonacci numbers using regexes (threes are wild)
on Oct 15, 2009 at 12:18
2 direct replies by blokhead
    perl -le'$;=3;$;=~s/./$&?30:3/eg for 3..pop;print length$;' 12
    Replace command-line argument 12 with any positive integer N to get the Nth Fibonacci number. Starts getting pretty slow for me after N=30, by the nature of the algorithm.

    Can you see how it works?

    blokhead

JAPH with only goto (and some noise)
on Oct 09, 2009 at 04:41
2 direct replies by haoess
    perl -we 'goto qq.\010.x0x11.qq.Just another Perl hacker,\n.'

    -- Frank

 (1-10) of 300 Next entries--> 

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Login:
    Password
    remember me
    What's my password?
    Create A New User

    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (16)
    jdporter
    holli
    Gavin
    CardinalNumber
    kennethk
    thezip
    Eyck
    NodeReaper
    LanX
    ssandv
    je44ery
    BenHopkins
    MikeDexter
    pmqs
    Spakz
    pramod8785
    As of 2010-02-09 22:55 GMT
    Sections?
    The Monastery Gates
    Seekers of Perl Wisdom
    Meditations
    PerlMonks Discussion
    Categorized Q&A
    Tutorials
    Obfuscated Code
    Perl Poetry
    Cool Uses for Perl
    Perl News
    Information?
    PerlMonks FAQ
    Guide to the Monastery
    What's New at PerlMonks
    Voting/Experience System
    Tutorials
    Reviews
    Library
    Perl FAQs
    Other Info Sources
    Find Nodes?
    Nodes You Wrote
    Super Search
    List Nodes By Users
    Newest Nodes
    Recently Active Threads
    Selected Best Nodes
    Best Nodes
    Worst Nodes
    Saints in our Book
    Leftovers?
    The St. Larry Wall Shrine
    Offering Plate
    Awards
    Craft
    Snippets Section
    Code Catacombs
    Quests
    Editor Requests
    Buy PerlMonks Gear
    PerlMonks Merchandise
    Planet Perl
    Perlsphere
    Use Perl
    Perl.com
    Perl 5 Wiki
    Perl Jobs
    Perl Mongers
    Perl Directory
    Perl documentation
    CPAN
    Random Node
    Voting Booth?

    What level of existential comfort do you require?

    Palace
    Executive suite at the best hotel
    Regular hotel in a decent part of town
    Motel
    Boarding house
    Sleeping Bag on Couch in Basement
    Any port in a storm
    Camping under the freeway overpass
    Jail
    Other

    Results (283 votes), past polls