in reply to conditional string formatting
I'm not sure this is in any sense "simpler" (it certainly burns a lot more computrons than just checking the length and selecting a format string conditionally), but:
See sprintf for format specifiers.c:\@Work\Perl\monks>perl -wMstrict -le "my @names = qw(A AB ABC ABCD); ;; for my $name (@names) { my $s = sprintf '%4s', sprintf '%-3s', $name; print qq{'$s'}; } " ' A ' ' AB ' ' ABC' 'ABCD'
Give a man a fish: <%-(-(-(-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: conditional string formatting
by Discipulus (Canon) on Jun 08, 2015 at 18:40 UTC | |
by AnomalousMonk (Archbishop) on Jun 08, 2015 at 20:44 UTC | |
by karlgoethebier (Abbot) on Jun 08, 2015 at 21:46 UTC |