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: <%-(-(-(-<
In reply to Re: conditional string formatting
by AnomalousMonk
in thread conditional string formatting
by docdurdee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |