in reply to Re: Overloading print()
in thread Overloading print()

almut++ ... a truly edifying piece of code which does exactly what I was after.

However, looking at the hoops it jumps through, I start to wonder about its portability and reliability. (Could it potentially create more problems for me than it solves ?)

And I couldn't work out how to restore the original stdout on perl 5.6 (where ">&" is not understood) - though that's not really a major consideration.

So ... I'm not yet sure whether I'll implement that approach, but thanks for going to the trouble of presenting such a well written and useful demo.

Math::MPFR already overloads "". The version on CPAN doesn't render inf, nan, and -0 as it should, though that's taken care of in the next release. Apart from that, the only difference (I'm aware of) between the overloaded "" and mpfr_out_str is that mpfr_out_str doesn't strip trailing zeros, whereas perl *does* strip them. (That is, whereas mpfr_out_str might render a number as  1.23450000e1, the overloaded "" will return 1.2345e1.) I don't see any need to be concerned about that discrepancy. The appeal of having the overloaded "" wrap mpfr_out_str is simply that I can then be certain that the outputs will match ... without even having to consider the many-and-varied "what if" scenarios.

Cheers,
Rob