Skip to content

Commit

Permalink
[S32::Str] split off substr-rw
Browse files Browse the repository at this point in the history
that way you only pay for what you use
  • Loading branch information
moritz committed May 17, 2012
1 parent 1b8b0ab commit f7e01b5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions S32-setting-library/Str.pod
Expand Up @@ -528,14 +528,15 @@ it is illegal for the start position to be outside of the string, it
is allowed for the final position to be off the end of the string; in
this case the entire rest of the string is returned, whatever is available.

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

$string ~~ /(barney)/;
substr($string, $0.from, $0.to) = "fred";
multi sub substr-rw($s is rw, $from = 0; $chars = $s.chars - $from)

A version of C<substr> that returns a writable reference to a part of a
string variable:

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

=item trim

Expand Down

0 comments on commit f7e01b5

Please sign in to comment.