Strange printf behavior

B

Bob Walton

Perl: Activestate build 806 (5.8.0)
OS: Windows 98SE

I note that:

perl -e "printf '%0d %0d',1,2;"

gives: 1 2

but that:

perl -e "printf '%d %d',1,2;"

gives: d

and that:

perl -e "printf '%d %0d',1,2;"

gives: 0d

and that:

perl -e "printf '%d %garbage',1,2;"

gives: garbage

Does anyone else observe this behavior and, if so, have an explanation?

I note that Perl 5.6.1 for Cygwin (B20) does not exhibit this problem.

Thanks.
 
S

Sisyphus

Bob said:
Perl: Activestate build 806 (5.8.0)
OS: Windows 98SE

I note that:

perl -e "printf '%0d %0d',1,2;"

gives: 1 2

but that:

perl -e "printf '%d %d',1,2;"

gives: d

and that:

perl -e "printf '%d %0d',1,2;"

gives: 0d

and that:

perl -e "printf '%d %garbage',1,2;"

gives: garbage

Does anyone else observe this behavior and, if so, have an explanation?

Not getting that with build 802 on Win2k - it seems to be quite ok (in
both command.com and cmd.exe shells).

Also nothing strange with AS build 626 (perl 5.6.1).

Cheers,
Rob
 
J

Jay Tilton

: Perl: Activestate build 806 (5.8.0)
: OS: Windows 98SE
:
: I note that:
:
: perl -e "printf '%0d %0d',1,2;"
:
: gives: 1 2
:
: but that:
:
: perl -e "printf '%d %d',1,2;"
:
: gives: d
:
: and that:
:
: perl -e "printf '%d %0d',1,2;"
:
: gives: 0d
:
: and that:
:
: perl -e "printf '%d %garbage',1,2;"
:
: gives: garbage
:
: Does anyone else observe this behavior and, if so, have an explanation?

The '%' character is meaningful to the command interpreter. It is used
to interpolate environment variables.

Double up a '%' character to ensure the shell doesn't try to do any
interpolation, e.g.

perl -e "printf '%%d %%d',1,2;"
 
B

Bob Walton

Jay said:
: Perl: Activestate build 806 (5.8.0)
: OS: Windows 98SE
:
: I note that:
:
: perl -e "printf '%0d %0d',1,2;"
:
: gives: 1 2
:
: but that:
:
: perl -e "printf '%d %d',1,2;"
:
: gives: d
:
: and that:
:
: perl -e "printf '%d %0d',1,2;"
:
: gives: 0d
:
: and that:
:
: perl -e "printf '%d %garbage',1,2;"
:
: gives: garbage
:
: Does anyone else observe this behavior and, if so, have an explanation?

The '%' character is meaningful to the command interpreter. It is used
to interpolate environment variables.

Double up a '%' character to ensure the shell doesn't try to do any
interpolation, e.g.

perl -e "printf '%%d %%d',1,2;"

Ah, missed that one! Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top