sprintf bug?

Discussion in 'Ruby' started by Daniel DeLorme, Feb 1, 2008.

  1. 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
     
    Daniel DeLorme, Feb 1, 2008
    #1
    1. Advertising

  2. 2008/2/1, 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?


    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

    --
    use.inject do |as, often| as.you_can - without end
     
    Robert Klemme, Feb 1, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Hubbart

    sprintf bug in 1.9.0?

    Mark Hubbart, Feb 16, 2004, in forum: Ruby
    Replies:
    5
    Views:
    229
  2. jwesley

    Sprintf bug

    jwesley, Nov 11, 2005, in forum: Ruby
    Replies:
    8
    Views:
    170
  3. Replies:
    4
    Views:
    191
    Leslie Viljoen
    Jul 29, 2006
  4. Wes Gamble

    Bug in sprintf?

    Wes Gamble, Aug 18, 2006, in forum: Ruby
    Replies:
    23
    Views:
    337
    Hal Fulton
    Aug 20, 2006
  5. Peter Szinek

    sprintf bug (?)

    Peter Szinek, Nov 11, 2006, in forum: Ruby
    Replies:
    8
    Views:
    185
    Bernard Kenik
    Nov 14, 2006
Loading...

Share This Page