I have this code
#!/usr/bin/perl
use strict;
my @a = ("b","a","d","c");
my %h = ("a",1,"b",2,"c",3,"d",4);
#print '"' . join('","', @a), "\"\n";
print "\n";
foreach my $key (@a) {
print '"' . $h{$key} . '",';
}
print "\n";
that outputs
"2","1","4","3",
but I would like that it just outputted
"2","1","4","3"
Notice that last ',' isn't there.
Is it possible to e.g. print a hash in a specific order, or some other trick to get the output I want?
Update:
Based on friedo's answer I was able to get it right.
print '"' . join('","', @h{@a}), "\"\n";
Friedo's answer doesn't have the quotes around the values.