in reply to (s)printf question: eliminating plus sign before zeros

There is no printf format which does that, so far as I know. Your solution is about what you need to do. It can be simplified a bit, printf +( $_ ? '%+4d' : '%4d' ), $_ for @nums;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: (s)printf question: eliminating plus sign before zeros
by Not_a_Number (Prior) on Dec 17, 2003 at 22:04 UTC

    Zaxo++

    In fact, playing with your solution, I can 'simplify' it further

    printf $_ ? '%+4d' : '%4d', $_ for @nums;

    But that's starting to look like golf...

    dave

      Did someone mention golf:)

      printf $_ ? '%+4d' : ' 0', $_ for -4 .. +4; -4 -3 -2 -1 0 +1 +2 +3 +4

      Actually it doesn't shorten the code any, but it maybe saves a few microseconds in parsing, both by the computer and the human being. Maybe?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      Hooray!