in reply to Re: conditional string formatting
in thread conditional string formatting
++Very nice, and very easily extended to handle a default case!
c:\@Work\Perl\monks>perl -wMstrict -le "my %formats = ( 1 => ' %s ', 2 => ' %s ', 3 => ' %s', 4 => '%s', +); ;; for my $x ('a', 'bc', 'def', 'ghij', 'klmno') { printf qq{'@{[ $formats{length($x)} // '%4.4s' ]}' \n}, $x; } " ' a ' ' bc ' ' def' 'ghij' 'klmn'
Give a man a fish: <%-(-(-(-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: conditional string formatting
by QM (Parson) on Jun 10, 2015 at 08:39 UTC | |
by AnomalousMonk (Archbishop) on Jun 10, 2015 at 14:00 UTC |