in reply to rounding off all members of a hash

Here's another idea: use tie.

To explain myself some more:

Create a module, in there you create a hash, and make the tie method accept a param called 'rounded', which has a true/false value.

Then tie it to two hashes, in your example, you tie the hash %stats to the module, with the rounded param set to false, and tie the hash %rounded_stats to the same module, but with the rounded param set to true.

Then implement the FETCH, and VALUES method to check the value of the rounded-param...

This would have the advantage that your data is only stored once (this also means it is in sync at all time), but it would also mean that fetching a value might be a bit slower/less efficient (since it has to do the sprintf)...

I can't tell what would be best, creating a real hash vs tieing it to two hashes, since that really depends on how you are planning on using it...

(References: `perldoc -f tie`, `perldoc perltie`, and `perldoc Tie::Hash`)

Replies are listed 'Best First'.
Re^2: rounding off all members of a hash
by Keystroke (Scribe) on May 04, 2005 at 18:56 UTC
    Animator's text gave me inspiration to go create a tied hash module just for the learning experience.
    Included below.