in reply to rounding off all members of a hash

That way is fine. I might have mapped instead:

my %rounded_stats = map { $_ => sprintf '%.2f', $stats{$_} } keys %stats;
That eliminates some temporary lexical variables which aren't really needed. (They could be eliminated in the explicit loop, too.)

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: rounding off all members of a hash
by qef (Initiate) on May 04, 2005 at 08:09 UTC
    Another way to do the actual rounding is to use Math::Round. The nearest() function can round to a whatever acuracy you want. This does the same as the sprintf() version, except that the results are numbers, so you don't get trailing '0' characters in the output:
    my %rounded_stats = map { $_ => nearest(0.01, $stats{$_}) } keys %stats;
Re^2: rounding off all members of a hash
by vindaloo (Acolyte) on May 04, 2005 at 04:02 UTC
    It seemed long. I need to think about using map more. thanks