Skip to content

Commit bcc126b

Browse files
authored
Improved explanation
1 parent cb4c913 commit bcc126b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

doc/Language/faq.pod6

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ not. The C<s///> operator works on a variable, into which it puts a newly
302302
created string object. Likewise, C<$i++> works on the C<$i> variable, not
303303
just on the value in it.
304304
305-
So, you cannot do the following, because they try to change the original C<Str>:
305+
Knowing this, you would not try to change a literal string (e.g. like
306+
C<'hello' ~~ s/h/H/; #doesn't work>), but you might accidentally do
307+
something equivalent using `map`:
306308
307309
my @foo = <hello world>.map: { s/h/H/} ; # dies with
308310
# Cannot modify an immutable Str (hello)
@@ -312,8 +314,7 @@ So, you cannot do the following, because they try to change the original C<Str>:
312314
# the following candidates match the type but require
313315
# mutable arguments: ...
314316
315-
But if you use an operator that returns a new value instead of changing the
316-
original, you can acheive your goal:
317+
Instead, use an operator that returns a new value instead of changing the original:
317318
318319
my @foo = <hello world>.map: { .subst('h','H')}; # ['Hello','world']
319320
my @bar = <hello world>.map: { .uc }; # ['HELLO','WORLD']

0 commit comments

Comments
 (0)