in reply to Need some help with Hashes and formatting
This statement
printf "%10s\t=>%10s\n" x @ky, @ky,
@vals;
is first outputting all keys, then all values.
Here's an alternative without the intermediate arrays, using the defined or operator // to
avoid a warning on an undef value.
#!/usr/bin/env perl use strict; use warnings; my %hash = ("fred" => "flintstone", "dino" => undef, "barney" => "rubble", "betty" => "rubble", ); printf "%10s\t=>%10s\n", "keys", "values"; for ( keys %hash ) { printf "%10s\t=>%10s\n", $_, $hash{$_} // ''; }
|
---|
In Section
Seekers of Perl Wisdom