Strange printf behavior

Discussion in 'Perl Misc' started by Bob Walton, Oct 13, 2003.

  1. Bob Walton

    Bob Walton Guest

    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.
    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
    Bob Walton, Oct 13, 2003
    #1
    1. Advertising

  2. Bob Walton

    Sisyphus Guest

    Bob Walton wrote:
    > 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

    --
    To reply by email u have to take out the u in kalinaubears.
    Sisyphus, Oct 13, 2003
    #2
    1. Advertising

  3. Bob Walton

    Jay Tilton Guest

    Bob Walton <> wrote:

    : 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;"
    Jay Tilton, Oct 13, 2003
    #3
  4. Bob Walton

    Bob Walton Guest

    Jay Tilton wrote:

    > Bob Walton <> wrote:
    >
    > : 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!

    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
    Bob Walton, Oct 14, 2003
    #4
    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. ben
    Replies:
    4
    Views:
    615
    Martin Ambuhl
    Jun 26, 2004
  2. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,241
  3. pai

    behavior of printf

    pai, May 1, 2006, in forum: C Programming
    Replies:
    4
    Views:
    263
    Coos Haak
    May 2, 2006
  4. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    431
  5. guru
    Replies:
    8
    Views:
    281
Loading...

Share This Page