Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Felling a tree JAPH

by MidLifeXis (Monsignor)
on Aug 30, 2013 at 14:28 UTC ( [id://1051644]=obfuscated: print w/replies, xml ) Need Help??

Still not a great JAPH, and it exceeds 4x79, but it is more obfuscated than yesterday's.

# Cutting down a tree $t=t->p;$t->g;$t->f;sub t::p{@n=map{x($_)}'Just another Perl hacker,'= +~m/(.)/g; bless{n=>\@n},$_[0]}sub t::g{$_[0]->{t}=$_[0]->f(0,$#{$_[0]->{n}});$_[ +0]->{n}=1 ;$_[0]}sub t::f{($a,$b,$e)=@_;$m=int(($b+$e)/2);$f=$_[0]->{n}[$m];$l=$ +_[0]->f( $b,$m-1)if$b<$m;$r=$_[0]->f($m+1,$e)if$m<$e;bless [$l,$f,$r],'f'}sub t +::f{$_[0] ->{t}=1}sub x{bless \$_[0],"x"}sub x::DESTROY{print${$_[0]}}sub f::DES +TROY{$_[0 ]->[$_]=1 for(0..2)}


Replies are listed 'Best First'.
Re: Felling a tree JAPH
by Grimy (Pilgrim) on Sep 03, 2013 at 20:28 UTC
    Which version of Perl are you using? I am getting the following outputs:
    ~$ perl5.10.1 japh r Perl hacker,Just anothe ~$ perl5.16 japh er Perl hacker,Just anoth

      Interesting. 5.8.9, Windows.

      $ perl Just another Perl hacker,

      Do you get the same results every time, or does it change on each run?

      Update: s/Win/Windows/ for clarity :-)


        For a given version, I get a consistent result. I reckon the discrepancies between different version are due to internal changes to the GC.

        Relying on DESTROY is problematic, because the order in which thingies are GC’d is unspecified.

Re: Felling a tree JAPH
by Grimy (Pilgrim) on Sep 04, 2013 at 14:17 UTC

    This 4x48 snippet prints JAPH on all Perl version I tested it on.

    sub'DESTROY{print${sub'_(_){bless\pop}pop}->[0]} _[J,_[q q q,_[o^O,_[q[,]],_[k,_[r],_[e]],_[h,_[c ],_[a]]],_[P,_[n&_],_[r],_[e],],],_[u,_[a,_[h,_[ r],_[e],],_[n,_[t],_[o],],],_[q[s],_[$"],_[t]]]]

    It still uses the “chopping a tree” concept, but the tree is hard-coded, rather than being built dynamically based on a string.

    Here it is with indentation to evidence the tree’s structure:

    _[J, _[q[ ], _[q[ ], _[q[,]], _[k, _[r], _[e] ], _[h, _[c], _[a] ] ], _[P, _[l], _[r], _[e], ], ], _[u, _[a, _[h, _[r], _[e], ], _[n, _[t], _[o], ], ], _[q[s], _[q[ ]], _[t] ] ] ];
      $ perl -v This is perl, v5.8.8 built for msys $ perl Malformed prototype for main::_: _ at line 2.


        Well then, just replace this _ with a $. It should work the same way, I only chose _ for aesthetic reasons.

        EDIT: Never mind trying, it won’t work, actually. Here’s a fixed version:

        sub'DESTROY{print${sub'_($){bless\pop}pop}->[0]} _[J,_[q q q,_[o^O,_[q[,]],_[k,_[r],_[e]],_[h,_[c ],_[a]]],_[v80,_[l],_[r],_[e],],],_[u,_[a,_[h,_[ r],_[e],],_[n,_[t],_[o],],],_[q[s],_[$"],_[t]]]]
        Tested on 5.8, 5.10, 5.14 and 5.16.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://1051644]
Approved by Corion
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-06-14 11:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.