in reply to Need some help with Hashes and formatting

The first parameter after the x operator is expected to be a number - and the command is run as many times. If you provide an array, its count is considered for this count. The following @ky and @vals are just appended and the array of length 10 is fed as input to this huge command that prints out 10 strings. Hence you get this problem.

Also, there is no guarantee about the order of of keys and values when you fetch them separately. You will have to fetch the keys first and then print values corresponding to each key. Try this out...
my %hash = ("fred" => "flintstone", "dino" => undef, "barney" => "rubb +le", "betty" => "rubble"); my @keys = keys %hash; printf ("%10s\t=>%10s\n", "Keys", "Values"); map ((printf ("%10s\t=>%10s\n", $_, $hash{$_})), @keys);

Replies are listed 'Best First'.
Re^2: Need some help with Hashes and formatting
by choroba (Cardinal) on Jun 25, 2014 at 11:26 UTC
    there is no guarantee about the order of of keys and values when you fetch them separately
    I'd call the documentation a guarantee:
    So long as a given hash is unmodified you may rely on keys, values and each to repeatedly return the same order as each other.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks for correcting that! I never noticed that in the docs...