in reply to Can this script be Optimized?

How about this:
print join( ",\t" => my @kk=sort keys %$Hash ), $/; my $row = 0; my $items_in_row; do { $items_in_row = 0; my $v; for my $k (@kk){ if (defined ($v = $Hash->{$k}[$row])) { $items_in_row ++; }else{ $v=""; } print "$v\t" } print "$/"; $row++; } until $items_in_row == 0;
Produces the same output as your code.

Update: Another version:

print join( ",\t" => my @kk=sort keys %$Hash ), $/; my $items_in_row; my $row=0; do { $items_in_row = 0; my $v; print +(map{ if ( defined ($v = $Hash->{$_}[$row]) ){ $items_in_row++ ; "$v\t" }else{ "\t" } } @kk ), "$/"; $row++; } until $items_in_row == 0;

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^2: Can this script be Optimized?
by Anonymous Monk on May 01, 2014 at 06:11 UTC

    Thanks alot NetWallah, I knew there was no need for all the multiples for loops I was using.
    Timtoday takes the day.

      OK - one final (short/cryptic) version:
      print join( ",\t" => my @kk=sort keys %$Hash ), $/; for (my $i=0; scalar grep {+defined} (my @v=map {$Hash->{$_}[$i] } @kk + ) ; $i++){ print join ("\t", map {defined $_ ? $_:""}@v),"$/"; }

              What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                    -Larry Wall, 1992