Let’s take an example code:
foreach my $cmp_id ( sort { $a <=> $b } keys %totals )
{
print $cmp_id . ", ";
}
How to get the last element of the hash printed without a comma? And if possible, without string operations (substring or something similar).
Unless you need to do something else, you’re going a very long way around…
joinconcatenates an array using the delimiter given as the first argument, which is perfect for what you’re after.UPDATE
My solution does work, you need to provide more info in your question.
Add the keys to an array, and print them when you’re done, i.e.: