Hello Liz, On Sun, Sep 07, 2025 at 11:02:10AM +0200, Elizabeth Mattijsen wrote: > > my $content = "example.txt".IO.slurp; # Read file > > $content ~~ s/Hello/Hi/; # Modify content > > spurt $filename, $content; # Write back to file
> FWIW, I don't know why that example isn't doing > $filename.IO.spurt($content) this is a really interesting question because I have to admit I prefer the one of the exemple but I don't know how biased is my explaination. I would say I found it a little less noisy and harder to edit but the difference is so thin to me I don't mind. but I would like to write spurt $content, $filename with multimethod spurt $filename # which would be spurt $_, $filename > $filename.IO.spurt( "example.txt".IO.slurp.subst("Hello","Hi") ) > > but it we were able to write this: > > > > with "example.txt".IO.slurp { > > s/Hello/Hi/; > > .&spurt: $filename; > > } > > > I really dislike indirect object syntax used this way. I love it because it's a way to declare a method without monkey-patching > What does this bring? Why not just $filename.spurt($_) ? Again: I feel it's less noisy .&spurt: $filename; $_.spurt($filename); I can't explain the core of it and as I say: I probably use both without noticing. > > with "example.txt".IO.slurp { > > s/Hello/Hi/; > > .spurt: $filename; > > } > > Now *that* I find to be an interesting idea. The oneliner would then become: > > "example.txt".IO.slurp.subst("Hello","Hi").spurt($filename) > > which has a nice left-to-right feel. Which would be indeed my syntax of choice. amicalement, -- Marc Chantreux
signature.asc
Description: PGP signature