in reply to substr and strings on the outside
Or do you want the new string to go in at exactly position 5, even if the old string is shorter than that? Then:my $f = " "; substr($f, length $f, length $f, "12345");
Having said that, this all may betray my failure to understand the question, since one could get the same result withmy $f = " "; my $l = length $f; substr($f, $l, $l, " " x ($l<5 ? 5-$l : 0) . "12345");
|
|---|