switched to use array to pass postorder, and using all the regex special vars, but their dynamic scoping doesn't work well in recursive function, ;(
#!perl -l
sub f{my($i,@p)=@_;$i=~/$p[0]/;my($l,$r,$t,$j)=($`,$',$&,$-[0]);@p>2?f($l,@p[1..$j]).f($r,@p[$j+1..$#p]).$t:$l.$r.$t}print f pop,pop=~/./g
|
doh, left multi-char var names in first one
#!perl -l
sub f{my$p=pop;my$t=substr$p,0,1;my($l,$r)=split/$t/,pop;$g=length$l;my($y,$z)=$p=~/.(.{$g})(.*)/;$p=~/../?f($l,$y).f($r,$z).$t:$p}print f@ARGV
|
Getting on the board at least, ;)
#!perl -l
sub f{my$p=pop;my$t=substr$p,0,1;my($il,$ir)=split/$t/,pop;$g=length$il;my($pl,$pr)=$p=~/.(.{$g})(.*)/;$p=~/../?f($il,$pl).f($ir,$pr).$t:$p}print f@ARGV
|