By using a sprintf parameter to determine the width:
my $str = '1234567890' x 6; my $prefixLen; my $magicLimit = tie_me_a_scalar(sub { $max_width - $prefixLen }); printf "Prefix stuff %n%.*s", $prefixLen, $magicLimit, $str;
Update: corrected %*s to %.*s
In reply to Re^4: How to use sprintf %n formatting pattern
by hv
in thread How to use sprintf %n formatting pattern
by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |