Skip to content

Commit f7e01b5

Browse files
committed
[S32::Str] split off substr-rw
that way you only pay for what you use
1 parent 1b8b0ab commit f7e01b5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

S32-setting-library/Str.pod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,15 @@ it is illegal for the start position to be outside of the string, it
528528
is allowed for the final position to be off the end of the string; in
529529
this case the entire rest of the string is returned, whatever is available.
530530

531-
Optionally, you can use substr on the left hand side of an assignment
532-
like so:
531+
=item substr-rw
533532

534-
$string ~~ /(barney)/;
535-
substr($string, $0.from, $0.to) = "fred";
533+
multi sub substr-rw($s is rw, $from = 0; $chars = $s.chars - $from)
534+
535+
A version of C<substr> that returns a writable reference to a part of a
536+
string variable:
536537

537-
If the replacement string is longer or shorter than the matched sub-string,
538-
then the original string will be dynamically resized.
538+
$string ~~ /(barney)/;
539+
substr-rw($string, $0.from, $0.to) = "fred";
539540

540541
=item trim
541542

0 commit comments

Comments
 (0)