Why is Perl printf displaying a format specifier rather than a formatted number?

I am trying to debug a problem on a remote user site. We narrowed it down to a problem with formatted output in Perl. 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 is 5.8.1, and it seems to behave correctly.

Any guesses? Incorrect configuration? Module errors?

+3
source share
3 answers
It seems like this was a Perl build configuration problem. The perl assembly supports the `d_longdbl` option, which indicates whether long doubles are allowed or not. You can check if installed on your computer:
perl -V:d_longdbl

perldoc sprintf. .


Edit:

, . sprintf , - q, ll L, NOT L. L . D'.

, perl L . . ☹ ​​ .

FYI, C printf.

printf("The number is %lG\n", 0.001);
printf("The number is %LG\n", 0.001);

"", 0.001, , :

printf("The number is %LG\n", 0.001L);

-, C printf L. , Perl .

+2

sprintf :

, printf C sprintf. . sprintf(3) printf(3) .

IOW, , Perl , .

Perl sprintf :

%l . , GNU. , Unix, man 3 sprintf man 3 printf.

+7

, . :

pax> perl -e 'printf "Number: %q\n", 0.1'
Number: %q

, , , , , HyperSnap , . , , . , .

, 1G (wun jee) lG (ell jee), .

I notice that IG(eye jee) will print the text, not the number, but if they do not use a particularly bad font, this should be a recognizable difference.

By the way, I only have 5.10 to work, so this might be a version issue. However, it is difficult to imagine that there will be a significant difference between 5.8 and 5.8.1.

+4
source

Source: https://habr.com/ru/post/1764835/


All Articles