Performance optimization in function for datastructure mapping
The following code is about 35% faster (measured with Benchmark). The tricks:


no anonymous array created for $tmp.
explicit return removed.
variables created in place where their value is needed.


Some of the tricks added just a 3%, the first one seemed the most important. YMMV.

I experimented with $_ and maps, too, but it seems the plain old C-style loop is the fastest.

sub faster {
    my ($self, $columns, $rows) = @_;
    my $retval = {
        row_count   =&gt; my $row_count = @$rows,
        col_count   =&gt; my $col_count = @$columns,
    };
    for (my $col_index = 0 ; $col_index &lt; $col_count ; $col_index++) {
        my $tmp;
        for (my $row_index = 0 ; $row_index &lt; $row_count ; $row_index++) {
            $tmp-&gt;[$row_index] = $rows-&gt;[$row_index][$col_index];
        }
        $retval-&gt;{$columns-&gt;[$col_index]} = $tmp;
    }
    $retval
}