Welcome to my shift-fest.

Entry for "The Perl Journal" (Circle 1) in the 4th Annual
Obfuscated Perl Contest.
Philipp Hanes
philipp@cnct.com

I think the commented code is more likely to be followable than any
other explanation.
Also, deadline pressures do not allow a complete explication.
So, the truth is, if you figured it out, then I'm scared of you.
If you didn't, I'm not sure a step-by-step would be terribly
meaningful.

Basically, it's a lot of cruft with data embedded in it, which is
sorted out by passing to two subroutines.  Each one prints the
second param if the first is false (undef is fine).  Otherwise,
it assumes it's got a certain format and emits 3 things:
a processing of the first 3 items, the 4th param, and a similar
processing of the next 3 params.

I actually was unable to use some of the stranger things about "shift"
because I encountered what seems to be a Perl bug with shift and anon
array construction.  In the end, the actual fancy stuff was reduced to
what you see here.  I had grand plans for shift, but it doesn't behave
entirely consistenly in some situations, and I didn't really want to
have my entry depend on bugs or implementation details too much.

There follows a slightly cleaner version, with many things commented.
I admit I lost track at some point on some levels what was going where.

Some of the formatting in the final submission allowed me to do away
with the "+" signs in some things like @{+shift}, but they are in
this code.
=======================================================================

#!/usr/bin/perl
 
package shift;

# $shift::shift
$shift=[shift, ' ', xm, a], # a space

# more stuff as below
# @shift::shift
@shift = (
	  A, B, ["", o], "shift::shift", "u", x, ["", r], "shift::shift",
	  );

# shift::shift
sub shift {
    # returns the second item (which might be undef) if first is false
    return shift unless shift;

    # if we get here, we are 1-down on the parameters

    # calls the first param as a function
    # if it's true, calls istelf with the next arg (as an array from
    # arrayref) otherwise calls itself with @shift, instead

    &{+shift} (shift() ? @{+shift} : (@{shift}, shift))
	  . shift .
	    &{+shift} (shift() ? @{+shift} : (@{shift}, shift)) ;
}

package main;

# @main::shift
@shift = (
	  C, # not false, so drop through
	  shift, # tested for whether to use @{+shift} or @{shift}
	  [0, r,l], # used due to trueness of above
	  'shift::shift', # called with previous arg
	  l, # actually printed
	  "", # test for second call
	  [ # arg for next thing (::shift)
	    O, # okay, so keep going
	    "", # tested for whether to use @{+shift} or @{shift}
	    [ # arg for next thing (::shift)
	      O, # okay, so keep going
	      "", # tested for whether to use @{+shift} or @{shift}
	      $shift::shift, # a space... printed due to falsity
	      '::shift', # called with previous arg
	      J, # actually printed
	      shift, # test for second call
	      [@shift::shift], # ' ' used due to falseness of above
	      'shift::shift' # called with previous arg
	      ],  # used due to falseness of above
	    '::shift', # called with previous arg
	    n, # actually printed
	    shift, # test for second call
	    [shift, a.::shift(shift, l)], # o printed due to falsity
	    'shift::shift' # called with previous arg
	    ],
	  '::shift' # called second
	  );

# ::shift
sub shift {
    # returns the second item (which might be undef) if first is false
    return shift unless shift;

    # if we get here, we are 1-down on the parameters

    # calls the first param as a function
    # if it's true, calls itself with the next arg (as an array from
    # arrayref) otherwise calls itself with @shift, instead

	&{+shift} (shift() ? (@{shift}, shift) : @{+shift})
      . shift .
	    &{+shift} (shift() ? (@{shift}, shift) : @{+shift}) ;
}

# $::shift
$shift=[shift, e, xm, a];

print shift::shift( C, # not false, so drop through
		    a, # tested for whether to use @{+shift} or @{shift}
		    [0, T,l], # used due to trueness of above
		    'shift::shift', # called with previous arg
		    h, # actually printed
		    o, # test for second call
		    [ # arg for next thing (::shift)
		      O, # okay, so keep going
		      "", # tested for whether to use @{+shift} or @{shift}
		      $shift, # "e" used due to falseness of above
		      '::shift', # called with previous arg
		      ::shift (
			       A, shift, ["", " "], "shift::shift", "P", 0, ["", e], "shift::shift",
			     ),
		      1, # true...  so below will call with @::shift
		      $shift, # ignored due to truth of above
		      '::shift' # called with previous arg
		      ],
		    '::shift' # called second
		    );
