Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printf ("%*c"... possible problem #2786

Closed
p5pRT opened this issue Oct 31, 2000 · 8 comments
Closed

printf ("%*c"... possible problem #2786

p5pRT opened this issue Oct 31, 2000 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 31, 2000

Migrated from rt.perl.org#4556 (status was 'resolved')

Searchable as RT4556$

@p5pRT
Copy link
Author

p5pRT commented Oct 31, 2000

From [email protected]

Created by [email protected]

I believe there is a problem in the way perl handles field widths in
printf style format strings (especially w.r.t similar "C" handling).

perl -e 'printf ("%2c-\n", " ");'

should print out 2 spaces followed by a dash. ie. " -"

more simply​:

perl -e 'printf ("%c-\n", " ");'

does not print the space at all!

This also fails with perl 5.6.0 built for i586-linux.

Perl Info


Site configuration information for perl 5.00404:

Configured by fulko at Tue Aug 18 11:17:34 EDT 1998.

Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration:
  Platform:
    osname=sco_sv, osvers=3.2, archname=i386-sco_sv
    uname='sco_sv fulko 3.2 2 i386 '
    hint=previous, useposix=true, d_sigaction=define
    bincompat3=y useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize=' ', gccversion=
    cppflags='-w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include'
    ccflags ='-w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include'
    stdchar='unsigned char', d_stdstdio=undef, usevfork=false
    voidflags=15, castflags=0, d_casti32=undef, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib /usr/ccs/lib
    libs=-lintl -lsocket -lnsl -lndbm -ldbm -lld -lm -lc -lcrypt -lPW -lx
    libc=, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags=''
    cccdlflags='', lddlflags=''

Locally applied patches:
	


@INC for perl 5.00404:
	/usr/local/lib/perl5/i386-sco_sv/5.00404
	/usr/local/lib/perl5
	/usr/local/lib/perl5/site_perl/i386-sco_sv
	/usr/local/lib/perl5/site_perl
	.


Environment for perl 5.00404:
    HOME=/u/fulko
    LANG=C_C.C
    LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:/usr/progrerssive/lib:/usr/skunk/lib
    LOGDIR (unset)
    PATH=/u/local/bin:/bin:/usr/bin:/usr/dbin:/usr/ldbin:/usr/bin/X11:/u/snap7.0/bin:/usr/java/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/ksh


@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From [Unknown Contact. See original ticket]

On Oct 31, fulko@​wecan.com said​:

perl -e 'printf ("%2c-\n", " ");'

You're used to the C idiom of​:

  printf("%2c-", ' ');

where ' ' is not an actual space, but rather the number 32. The %c format
takes an integer, and converts it to the corresponding character.

perl -e 'printf ("%c-\n", " ");'

  jeffp@​friday [9​:27am] ~ #190> perl -lwe 'printf "<%c>", " "'
  Argument " " isn't numeric in prtf at -e line 1.
  jeffp@​friday [9​:27am] ~ #191> perl -lwe 'printf "<%c>", ord(" ")'
  < >

Why did Perl abbreviate 'printf' as 'prtf'?

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From @vanstyn

In <10010310919.aa08664@​wecan.com>, fulko@​wecan.com writes​:
:
:I believe there is a problem in the way perl handles field widths in
:printf style format strings (especially w.r.t similar "C" handling).
:
:perl -e 'printf ("%2c-\n", " ");'
:
:should print out 2 spaces followed by a dash. ie. " -"

No, it should format chr(" ") in a two character field. Now chr(" ") is
the same as chr(0), and perl does indeed print a space followed by a
zero byte followed by a dash.

If you turn on warnings, you will be given a clue to this​:
  Argument " " isn't numeric in printf at -e line 1.

You can also verify that the zero byte is printed by piping the output
to od(1) or similar.

Hope this helps,

Hugo

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From @JohnPeacock

Even stranger is why his code prints "fine" under NT​:

  D​:\>perl -we "printf ("""-%2c-\n""", """ """);"
  Argument " " isn't numeric in printf at -e line 1.
  - -

  D​:\>

John Peacock

Jeff Pinyan wrote​:

Why did Perl abbreviate 'printf' as 'prtf'?

--
Jeff "japhy" Pinyan japhy@​pobox.com http​://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine http​://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc. http​://www.perlarchive.com/
CPAN - #1 Perl Resource (my id​: PINYAN) http​://search.cpan.org/

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From [Unknown Contact. See original ticket]

Behind-the-scenes mail between John Peacock and myself
has confirmed that NT, too, is printing a blank and a byte of 0's,
which NT saw fit to display as two blanks.

That leaves the somewhat odd difference in the opcode.h tables,
UNIX with "prtf", NT with "printf". -- jpl

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From @jhi

On Tue, Oct 31, 2000 at 09​:29​:22AM -0500, Jeff Pinyan wrote​:

On Oct 31, fulko@​wecan.com said​:

perl -e 'printf ("%2c-\n", " ");'

You're used to the C idiom of​:

printf("%2c-", ' ');

where ' ' is not an actual space, but rather the number 32. The %c format
takes an integer, and converts it to the corresponding character.

perl -e 'printf ("%c-\n", " ");'

jeffp@​friday [9​:27am] ~ #190> perl -lwe 'printf "<%c>", " "'
Argument " " isn't numeric in prtf at -e line 1.
jeffp@​friday [9​:27am] ~ #191> perl -lwe 'printf "<%c>", ord(" ")'
< >

Why did Perl abbreviate 'printf' as 'prtf'?

Perl 5.6.0​:

$ perl -lwe 'printf "<%c>", " "'
Argument " " isn't numeric in printf at -e line 1.

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From @jhi

On Tue, Oct 31, 2000 at 10​:53​:59AM -0500, John P. Linderman wrote​:

Behind-the-scenes mail between John Peacock and myself
has confirmed that NT, too, is printing a blank and a byte of 0's,
which NT saw fit to display as two blanks.

That leaves the somewhat odd difference in the opcode.h tables,
UNIX with "prtf", NT with "printf". -- jpl

Which version of Perl on UNIX does this? As I noted at least 5.6.0
should have it right.

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2000

From [Unknown Contact. See original ticket]

On Tue, Oct 31, 2000 at 10​:53​:59AM -0500, John P. Linderman wrote​:

Behind-the-scenes mail between John Peacock and myself
has confirmed that NT, too, is printing a blank and a byte of 0's,
which NT saw fit to display as two blanks.

That leaves the somewhat odd difference in the opcode.h tables,
UNIX with "prtf", NT with "printf". -- jpl

Which version of Perl on UNIX does this? As I noted at least 5.6.0
should have it right.

--
$jhi++; # http​://www.iki.fi/jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen

This is perl, version 5.005_03 built for sgi6-irix

The curse of having too many versions of Perl on too many hosts,
many of which are not under my control. I cut-and-pasted the
original test code into the nearest window, and happened across
a ``bad'' one. Indeed, opcode.h is fine under 5.6 and 5.7.
Sorry -- jpl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant