... could you perhaps share the situation you're in where it would be handy for these two to behave differently?Firstly, I see what you mean by the expectation that
print $blessed_obj; and
print "$blessed_obj"; should do the same thing. (A nicely insightful observation :-)
My question came about this way:
In C, users of the mpfr library will output values to stdout using the
mpfr_out_str function - which prints directly to stdout (rather than return a string which one can then print to stdout). As regards Math::MPFR (which wraps the mpfr library function), I thought "Wouldn't it be nice if
print was overloaded to use
mpfr_out_str ... then C and Perl are guaranteed of producing the same output." But then, that would mean that every time someone did
$x = "$blessed_obj"; the value encapsulated in $blessed_obj is going to be printed to stdout ... and that's probably not what's intended :-)
Anyway, as you've just demonstrated, there's a very good reason that
print and
"" should be overloaded by the
same function ... so I think that's the end of that train of thought. Probably better to have
print and
"" overloaded by a function that returns a string that emulates the
mpfr_out_str output - as is currently the case. Only problem there is that, since the mpfr library itself doesn't provide such a function, I have to hand craft my own ... and therein lies the potential for discrepancies.
Thanks
jbert.
Cheers,
Rob