|
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. |
|||
|
01:15
discord-raku-bot left,
discord-raku-bot joined
01:20
Manifest0 left
02:48
MasterDuke joined
06:23
kjp left
06:26
kjp joined
08:59
Manifest0 joined
09:10
dakkar joined
11:40
snonux left
11:41
snonux joined
12:18
MasterDuke left
17:47
dakkar left
18:31
codesections left,
codesections joined
18:32
codesections left
18:33
codesections joined
18:36
codesections left,
codesections joined
18:40
codesections left,
codesections joined
18:41
codesections left,
codesections joined
18:43
codesections left,
codesections joined
18:51
codesections left,
codesections joined
18:54
codesections left,
codesections joined
18:55
codesections left
18:59
codesections joined
19:02
codesections left,
codesections joined
|
|||
| thowe | I can't seem to figure out how to do a simple string substitution... | 19:09 | |
| I have a capture from a regex $0. It isn't a string unless I do $0.Str. But I can't seem to figure out a way to make $0.Str work as the first arg for a subst call. | |||
| $line.subst(/$0.Str/'10'); | 19:10 | ||
| er $line.subst(/$0.Str/,'10'); | |||
| lizmat | $line.subst(/$0.Str()/,'10'); perhaps ? | 19:11 | |
| thowe | I have tried a number of variations | ||
| that one says Null Regex not allowed | |||
| I have also tried $($0.Str) | 19:12 | ||
| The only thing I can make work is to assign $0.Str to another variable and match against that | |||
| but there must be a way to not do the extra step | |||
| lizmat | m: "foo" ~~ /(o)/; say $0; say "foo".subst($0, "bar") | 19:13 | |
| camelia | ļ½¢oļ½£ fbaro |
||
| lizmat | .subst also takes literal strings, and $0 can be considered one | ||
| thowe | Hm, the docs made me think it had to be a regex... | 19:14 | |
| That works for me, but still has me wondering how I would put $0.Str into a regex | 19:15 | ||
| lizmat | remember that $0 is syntactic sugar for $/[0] | ||
| thowe | I don't remember that.. nor do I think I understand it | ||
| lizmat | and I'm not 100% sure whether a $/ inside a regex refers to its outer or to its inner | 19:16 | |
| the result of a match is in the Match object, aka $/ | 19:17 | ||
| thowe | ah | ||
| lizmat | and $0 is short for $/[0]: for positional captures, $/ acts as an array | 19:18 | |
| nahita3882 | one can refer to Raku code within a regex with <{...}> | ||
| and I tried that with $0.Str | |||
| but it turns out to be Nil | |||
| lizmat | $<foo> is short for $/<foo>: for named captures $/ acts as a hash | ||
| yeah, so $/ is already reset | 19:19 | ||
| docs.raku.org/language/regexes#$/_...is_matched <-- see some explanations | |||
| nahita3882 | so it refers to the inner one as lizmat suspects I guess | ||
| librasteve | m: my $line = '1234107'; say $line.subst(/'10'/, '0'); | 19:38 | |
| Raku eval | 123407 | ||
| librasteve | the find is first and the replacement is the second arg - as with any method / sub separate the args with a comma | 19:41 | |
| m: my $line = '1234107'; $line.subst(/2(.)/, $0.Str); | 19:45 | ||
| Raku eval | Use of Nil in string context in block <unit> at main.raku line 1 | ||
| librasteve | well that works on my repl | ||
| gives 134107 | 19:46 | ||
| nahita3882 | if you were to start a new session it wouldn't work I think | 19:57 | |
| it uses a previously calculated $0 there | 19:58 | ||
| if it worked. | |||
| m: say S/2(.)/$0/ given "1234107" | 19:59 | ||
| Raku eval | 134107 | ||
| nahita3882 | because $0.Str should be evaluated first, then it will be sent to the .subst method; when .subst's actual body did the regex match, it's too late | 20:01 | |
| thowe | does file.IO.lines do some kind of auto chomp? | 20:20 | |
| nahita3882 | it does by default, you can pass :!chomp | 20:21 | |
| thowe | ah... OK... that will clean this up a bit. | 20:22 | |
| So, my original file has CRLF line endings. I am now not chomping, but after printing the CRs appear to still have disappeared. | 20:30 | ||
| for $file.IO.lines :!chomp -> $line { print $line } <- Was CRLF, now is just LF. | 20:34 | ||
|
20:54
librasteve_ joined
|
|||
| thowe | The line ending is still being changed somewhere. I guess I need to continue to chomp and then add \r\n, which seems dirty, but gets the job done. | 20:55 | |
|
21:20
codesections left,
codesections joined
21:21
codesections left
21:22
codesections joined,
codesections left
21:24
codesections joined,
codesections left
21:27
codesections joined
21:32
codesections left
21:43
codesections joined
21:48
codesections left
22:51
teatwo left
22:52
teatwo joined
23:32
Manifest0 left
|
|||