in reply to Perl - write data from hashes

Are the keys in all the hashes always the same? If yes, here's an algorythm for you:

  1. Get the list of keys from any of the hashes, possibly sort it or make the Name key first somehow
  2. For each of the keys you got, print its name, then (joined by "\t" between them) its values from your collected hashes
  3. You'll probably want to use an array of hashes (read perlreftut and perldsc for more info) instead of just a bunch of numbered variables.
Example code using an array of hashes (untested):
for my $key ("Name", grep { $_ ne "Name" } keys %{$hashes[0]}) { print ((join "\t", $key, map { $_->{$key} } @hashes),"\n"); }
It could have been easier to print Name first it you didn't mix it with the other data.

Edit: forgot to print "\n"

Replies are listed 'Best First'.
Re^2: Perl - write data from hashes
by Happy-the-monk (Canon) on Oct 13, 2013 at 15:34 UTC

    joined by "\t" between

    in case that turns out less then perfect, resort to printf or sprintf

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)