Minor refinement; eliminate next for an if type construct.
#!perl -l
while(@ARGV){$_=pop;s/(.)//&&do{$o=$1.$o;pop=~/$1/;push@ARGV,$`,substr($_,0,length($`),''),$',$_}}print$o
|
Doh! No need for a function at all; just a while loop, and a manual stack manipulation.
#!perl
while(@ARGV){$_=pop;s/(.)//||next;$o=$1.$o;pop=~/$1/;push@ARGV,$`,substr($_,0,length($`),''),$',$_}print"$o
"
|
#!perl
sub q{my($p,$i)=@_;$p=~s/(.)//;$o=$1.$o;my($l,$r)=$i=~/(.*)$1(.*)/;$i=length($l)
;&q(substr($p,$i),$r)if$r;&q(substr($p,0,$i),$l)if$l;}&q(@ARGV);print"$o
"
|