my first D program (and benchmark against perl)

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 11 06:04:34 PST 2015


On Wednesday, 11 November 2015 at 13:32:00 UTC, perlancar wrote:
>     for (int rownum=0; rownum < table.length; rownum++) {
>         res ~= "|";
>         for (int colnum=0; colnum < table[rownum].length; 
> colnum++) {
>             res ~= leftJustify(table[rownum][colnum], 
> widths[colnum]);
>             res ~= "|";
>         }
>         res ~= "\n";

Not sure if this will be faster, but you could try rewriting the 
above for loop
with more functional code (code below is untested):

table.map!((col)
   { return zip(col,widths)
               .map!( (e) => leftJustify(e[0], e[1] ) )
               .join("|");
   }).join("\n");

Cheers,

Edwin


More information about the Digitalmars-d-learn mailing list