In the following sprintf:
I read perldoc perldiag, where the warning is explained:join(" & ", map { sprintf "%-8s (x%s)", $_, 0+@{$rel_hosts{$_}} } @rel +);
(W printf) There is a newline in a string to be left justified by printf or sprintf. The padding spaces will appear after the newline, which is probably not what you wanted. Usually you should remove the newline from the string and put formatting characters in the sprintf format.So following this advice, I decided that I needed to strip the newline(s) out and add them back in the %s. To help me understand the problem further, I tried to reproduce the error with the following code:
To my surprise this code did not generate the warning. Why not? And how can I make it do so?my @rel = ("test1", "test2", "test3"); my $test = join(" & ", map { sprintf "%-8s (x%s)", "$_\n"} @rel);
And how would you fix the original problem?
In reply to Newline in left-justified string for %s warning by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |