in reply to Re: Re: Odd behavior of $#
in thread Odd behavior of $#
Right, that case works because print itself is doing the conversion. If $# is set then each element passed to print is looked at to see if it can be converted to an IV or an NV. If it can, it's formatted using $#. Spaces don't matter when considering if it's numeric, so " 1.23456 " doesn't look any different than a numeric 1.23456 (and in fact the spaces will be stripped before the conversion is done).
$ perl -le '$#="%0.2f";$a=1.2345;print "|", " $a ", "|";' |1.23|
However in the other cases, there's more than spaces and digits (and decimals, and whatnot that perl recognizes as a numeric) so it's not seen as an IV or NV and not treated to the $# munging. See Perl_do_print in doio.c for the complete skinny on what exactly happens.
|
|---|