Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
i = (m-len(s))/2
j = (m - len(s)) - (m-len(s))/2
s = repeat(c,i) // s // repeat(c,j)
while (s.length() < m) s = c + s + c;
sub center {
my ($s, $m, $c) = @_;
my $slen = length $s;
return $s if $slen > $m;
$c //= ' ';
my $r = $c x $m;
my $p = int($m/2 - $slen/2);
substr($r, $p, $slen, $s);
return $r;
}
print center("abcd",10,"X");
s = s.center(m, c)
s = s.center(m, c)
let n = (m + s.len())/2;
s = format!("{s:X>n$}");
s = format!("{out:X<m$}");