sprintf bug?

D

Daniel DeLorme

I've just stumbled across the following:

machine1$ ruby -ve 'printf("(%*-s)\n", 10,"hello")'
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]
(hello )

machine2$ ruby -ve 'printf("(%*-s)\n", 10,"hello")'
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]
-e:1:in `printf': flag after width (ArgumentError)
from -e:1

I can fix it by changing the pattern to "%-*s", but is that a bug in
patchlevel 111 or is it a "bugfix" for a syntax that was never supposed
to be valid? And if the second case, what is the point of making things
more restrictive?

Daniel
 
R

Robert Klemme

2008/2/1 said:
I've just stumbled across the following:

machine1$ ruby -ve 'printf("(%*-s)\n", 10,"hello")'
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]
(hello )

machine2$ ruby -ve 'printf("(%*-s)\n", 10,"hello")'
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]
-e:1:in `printf': flag after width (ArgumentError)
from -e:1

I can fix it by changing the pattern to "%-*s", but is that a bug in
patchlevel 111 or is it a "bugfix" for a syntax that was never supposed
to be valid?

AFAIK valid syntax always has been this:

irb(main):002:0> sprintf "%*s", 10, "hello"
=> " hello"
irb(main):003:0> sprintf "%-*s", 10, "hello"
=> "hello "

So, it's a bugfix.
And if the second case, what is the point of making things
more restrictive?

I do not understand the question: if it is a bug fix then the new
behavior is the one that was originally intended. Code that employs
other syntax is simply broken.

Cheers

robert
 

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

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top