This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
antononcube I expect the following code to produce "and 23_321_900 this", not "and 23_321,900 this". Where I am wrong? How can I do that? ‌‌my $input = 'and 23,321,900 this'; $input.subst(/(\d) ',' (\d**3)/, {"$0_$1"}):g # and 23_321,900 this 21:02
I found a clunky solution. I still I do not understand why the adverb :g does not have effect. (I just have a few iffy conjectures...) 21:57
_elcaro_ I would just use a Capture Marker [0] > my $input = 'and 23,321,900 this'; and 23,321,900 this [1] > $input.subst(/',' )> \d**3 /, "_", :g) and 23_321_900 this 22:04
More verbose with look-around assertions: $input.subst(/','<?before \d**3> /, "_", :g) 22:06
nemokosch are you sure that adverb was even at a valid position? 22:09
_elcaro_ Yeah, it will still work with the adverb outside the parens 22:10
nemokosch well if it does, that's easier to validate 😼 ⌨️ 22:11
yep 22:12
_elcaro_ I think the problem with Anton's original expression is... since the match includes those 3 numbers, the cursor moves to the end of the match, so it can't then use the last digit in the beginning of the next match. I've often thought that having :exhaustive available on subst would be nice to have > say .Str for $input ~~ m:g/\d','(\d**3)/ 3,321 > say .Str for $input ~~ m:ex/\d','(\d**3)/ 3,321 1,900 22:20
antononcube My clunky solution is based on exhaustive match like yours. 22:24
It does make sense to use look around assertions instead. 22:25