in reply to conditional string formatting

There is no 'center' option for printf. You have to check the length:
printf +(3 < length $in ? q() : ' ') . '%-3s', $in

Or, more funny (and shorter):

printf ' ' x (4 > length $in) . '%-3s', $in
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: conditional string formatting
by docdurdee (Scribe) on Jun 08, 2015 at 17:51 UTC
    Thanks!