Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: (Golf) Building a Better Binary Tree

by trantor (Chaplain)
on Oct 08, 2001 at 19:53 UTC ( [id://117484] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub buildtree {
            my($f, @a) = @_;
            local $_;
    ...
            s/}$/)/;
            eval;
    }
    
  2. or download this
    #!/usr/bin/perl -w
    
    ...
    my %tree = buildtree( $func, @array );
    
    print Dumper \%tree;
    
  3. or download this
            #        1         2         3         4
            #23456789012345678901234567890123456789012345
            my$f=shift;@_=((sort{&$f($a,$b)}@_),'');$_=
            join'=>[0,{',@_;chop;%{eval"{$_ 0".']}'x$#_};