|
06:36
sibl joined
08:09
sibl left
10:34
deoac joined
|
|||
| deoac | I would like to do a string substitution (not a regex substitution) and learn how many substitutions were made. e.g. `my $s = 'foo'; $s .= subst('o', 'e', :g)` should change `$s` to `fee`. How do I know that 2 substituitons were made? | 10:43 | |
| lizmat | if the replacement string has a different size than the original, you could deduce it from the difference in string sizes of the modified string vs the original string | 10:52 | |
| deoac | That cant be guaranteed. | 10:53 | |
| lizmat | if they're the same... well, then you'd need to do a .match | 10:54 | |
| m: 'say "foobarbaz".match("o", :g).elems | |||
| camelia | ===SORRY!=== Error while compiling <tmp> Unable to parse expression in single quotes; couldn't find final "'" (corresponding starter was at line 1) at <tmp>:1 ------> 'say "foobarbaz".match("o", :g).elems<HERE><EOL> expecting any of: … |
||
| lizmat | m: say "foobarbaz".match("o", :g).elems | ||
| camelia | 2 | ||
| lizmat | or use a Callable as the replacement: | 10:56 | |
| m: my $c; say "foobarbaz".subst("o", { ++$c; "e" }, :g); say $c | |||
| camelia | feebarbaz 2 |
||
| deoac | `match` doesnt change the string. But I like the Callable solution, it's a new tool for me. Thank you. | 10:58 | |
| lizmat | yw | 10:59 | |
|
13:44
librasteve_ joined
14:11
deoac left
16:10
jgaz left
20:34
librasteve_ left
22:11
stanrifkin joined
23:37
cleo joined
|
|||