I think eric256 in Re: Create string with a delay and Zaxo in Re: Create string with a delay are both on the right track, but eric256's "len($a . $b . $c . $d . $x)" represents a separate pass through the complexity. For Zaxo's solution, the second argument of the sprintf needs to be "length($str)+10", calculated just before $x is added.
Combining and extending the two approaches a little, I'd suggests
Note that this automatically adjusts for the length of the "fill-in" zeroes, if we change that part in a later revision, usually a good idea. Also the code still works if we insert a "$str .= $aplus", somewhere in the complexities of assembling the first part of the string.$str = $a . $b . $c .$d; $xpos_spot = length( $str ); $e = '0000000000'; $xpos_len = length($e); $str .= $e; $str .= $f; ... $str .= $w; substr $str, $xpos_spot, $xpos_len, sprintf('%${xpos_len}d',length($str)); $str .= $x; ...
There's a way to set up a kind of pointer into the part of the string you want to modify later, one that you can assign to. It uses a reference to "substr" with pre-defined parameters (known as currying). See BrowserUK's excellent Re: lhs substr(): refs vs. scalars writeup.
In reply to Re: Create string with a delay
by rodion
in thread Create string with a delay
by jeanluca
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |