I just bet that my @labels = sort keys %hash worked just fine didnt it? Your problem was that when you said tried to get the contents they didnt line up. So what you want is to line up the values of @contents with the values in @labels. It would have been nice if you showed us what you did try, but at one point i expect you had something like
my @labels; my @content;
for my $var (keys(%hash)){
push @labels,$var;
push @content,$hash{$var};
}
and that was when you were complaining they were random.
so what if i mentioned that keys %hash looks like an array. in fact you could have said my @arr=keys(%hash); for my $var(@arr) { ... }. And you have seen that sort in fact does sort character values like you want. so what if you said my @arr=keys sort(%hash); for my $var(@arr) { ... } what do you think would happen?. So lets go a step farther, keys looks like an array, sort takes an array and looks like an array. we could just double things up, for my $var(sort(keys(@arr))) { ... }