in reply to Dynamic menu generation

This seems to do the trick:
my @array = ( 'Main//News', 'Main//Reviews//PC', 'Main//Reviews//PS2', 'Main//Reviews//XBox', 'Other Menu//Other//Sub//Menus' ); sub menu { $_=q~;ir$w}Uw&Ii,jmcumUumbo#e_cjm>oImb}U|nyp@''@#l"ynrjmUtthU]h!U[$rhb +]h!U[11mU=mboI|_|mU#|wU"mcuL)'(*=L#/l"ynrjmU)mboI|wU"mUuhb]mU[#|wU"mc +uL)(*=)*<=hU]-s[)'*<=L#//f_y${sumc#/#tir$w~;y~L)oep<;@y>m}/Ushw![i=nb +$1*l#_&|{"]u('f,tjIcr~"<)ftI*'i_@=}s1$u#]m>lcn|Lw;obp!h[,U/jy&({re~;s +,.*,$&,ee;$_ } print menu(sort@array),$/;
If you don't pass in a sorted array, it can create strange menus. It's also easily confused by similar leaf nodes.

Replies are listed 'Best First'.
Re: Re: Dynamic menu generation
by webengr (Pilgrim) on Oct 31, 2002 at 05:32 UTC

    Okay, I am mystified (and if need be, humbled). I have seen this sort of genuinely obfuscated thing before (in someone's .sig file perhaps?) and even confirmed that it worked.

    What I am wondering though, is how the heck do you come up with code like,

    $_=q~;ir$w}Uw&Ii,jmcumUumbo#e_cjm>oImb}U|nyp@''@#l"ynrjmUtthU]h!U[$rhb +]h!U[11mU=mboI|_|mU#|wU"mcuL)'(*=L#/l"ynrjmU)mboI|wU"mUuhb]mU[#|wU"mc +uL)(*=)*<=hU]-s[)'*<=L#//f_y${sumc#/#tir$w~;y~L)oep<;@y>m}/Ushw![i=nb +$1*l#_&|{"]u('f,tjIcr~"<)ftI*'i_@=}s1$u#]m>lcn|Lw;obp!h[,U/jy&({re~;s +,.*,$&,ee;$_

    I mean, I can't even recognize many operators in that mess, let alone interpret jmcumUumbo#e_cjm into anything meaningful. Also, I could not get this to work.

    Clues for the clueless? Or perhaps I am missing some larger joke.



    PCS
      The 'mess' should not be interpreted literally.

      Hint 1: read perlop wrt to quoting operators.

      rdfield

      The first two statement in sub menu are:
      $_ = q~ stuff ~; y~ characters ~ other characters ~;
      If you insert a "print;" here you will be a lot less mystified.
      It works, but you'll have to be careful about how you copy it. Perl Monks inserts red plus signs (+) to break up the lines, that if pasted in to the program will cause it to fail. You can edit these out if you're careful, and join the program back in to one line, or use the "D/L Code" link to get a clean copy.

      Now, this is intentionally obfuscated, but the non-obfuscated source isn't that much clearer. Here's the encoded program that is being run:
      *menu=sub{my(@r,@s,@c);for(@_){@c=split'//';while(@s&&$s[$#s]ne$c[$#s]||@s>@c){pop@s;push@r,"</UL>";}while(@s<@c){push@s,$c[@s];push@r,"<UL><LI>$s[-1]</LI>";}}join!1,@r;};&menu