I’m trying to debug a problem on a remote user’s site. We’ve narrowed it down to a problem with formatted output in Perl. The user swears up and down that
perl -e 'printf "Number: %lG\n", 0.1'
prints
Number: %lG
not
Number: 0.1
The user reports that their Perl is version 5.8. The oldest version I have around is 5.8.1, and it seems to behave correctly.
Any guesses? Misconfiguration? Module conflicts?
It looks like it was a Perl build configuration issue. The Perl build supports a `d_longdbl` option, which indicates whether long doubles are allowed or not. You can test whether it is set on your machine with:
More info at perldoc sprintf.
Thanks for your input everybody.
Edit:
Nope, that wasn’t it either. Close inspection of the sprintf documentation revealed that the modifiers for a long double are
q,ll, andL, NOTl.lis a valid modifer for integer types. D’oh.It looks like most installations of perl will silently ignore the
l, and parse the rest of the modifier correctly. Except on our user’s site. ☹ Anyway, the problem was fixed by using a valid modifier for a long double.FYI, I played with the same format specifiers in the C
printf.The first call “worked”, printing out
0.001, but the second call printed out a garbage value until I properly specified the type of the numeric literal:Apparently the C
printfis silently ignoring the improperlmodifier. This makes me suspect that most Perl installations ignore it too.