Re: How to do a substring replacement in Perl 6
Hi all! From http://perldoc.perl.org/functions/substr.html: substr has a 4th argument (or you can use substr as an lvalue) for replacement. substr EXPR,OFFSET,LENGTH,REPLACEMENT From http://doc.perl6.org/routine/substr I don't see any way to do a replacement. What is the idiomatic way of doing a positional string replacement in Perl 6? Thanks! Method form: $ perl6 -e 'my $s = abc; $s.substr-rw(1,1) = z; say $s;' azc Function form: $ perl6 -e 'my $s = abc; substr-rw($s, 1,1) = z; say $s;' azc I also do not see substr-rw in doc.perl6.org. It needs to be added. In the meantime, you can find it here: http://design.perl6.org/S32/Str.html thanks, Bruce, for the examples! I've added these to the doc.perl6.org documentation. The entry for substr-rw should appear in roughly half an hour. Cheers, Paul
Re: How to do a substring replacement in Perl 6
On Jun 8, 2015, at 3:51 PM, Douglas E. Miles d...@veritablesoftware.com wrote: Hi all! From http://perldoc.perl.org/functions/substr.html: substr has a 4th argument (or you can use substr as an lvalue) for replacement. substr EXPR,OFFSET,LENGTH,REPLACEMENT From http://doc.perl6.org/routine/substr I don't see any way to do a replacement. What is the idiomatic way of doing a positional string replacement in Perl 6? Thanks! Method form: $ perl6 -e 'my $s = abc; $s.substr-rw(1,1) = z; say $s;' azc Function form: $ perl6 -e 'my $s = abc; substr-rw($s, 1,1) = z; say $s;' azc I also do not see substr-rw in doc.perl6.org. It needs to be added. In the meantime, you can find it here: http://design.perl6.org/S32/Str.html — Hope this helps, Bruce Gray (Util of PerlMonks)
Re: How to do a substring replacement in Perl 6
Hi Douglas, From http://perldoc.perl.org/functions/substr.html: substr has a 4th argument (or you can use substr as an lvalue) for replacement. substr EXPR,OFFSET,LENGTH,REPLACEMENT From http://doc.perl6.org/routine/substr I don't see any way to do a replacement. What is the idiomatic way of doing a positional string replacement in Perl 6? Thanks! I believe `substr-rw` is what you're looking for: $ perl6 my $s = The black cat climbed the green tree; The black cat climbed the green tree my $z = substr-rw($s, 14, 7) = jumped from; jumped $s.say The black cat jumped from the green tree As far as I know, not all of its behaviour has been implemented yet (FWIW it looks like it shouldn't have returned jumped above; my guess is that it should have been climbed. Nevertheless, it seems to do that which you're looking for. Hope that helps! Cheers, Paul
Re: How to do a substring replacement in Perl 6
Thanks Paul! On 6/8/2015 2:46 PM, Paul Cochrane wrote: Hi Douglas, From http://perldoc.perl.org/functions/substr.html: substr has a 4th argument (or you can use substr as an lvalue) for replacement. substr EXPR,OFFSET,LENGTH,REPLACEMENT From http://doc.perl6.org/routine/substr I don't see any way to do a replacement. What is the idiomatic way of doing a positional string replacement in Perl 6? Thanks! I believe `substr-rw` is what you're looking for: $ perl6 my $s = The black cat climbed the green tree; The black cat climbed the green tree my $z = substr-rw($s, 14, 7) = jumped from; jumped $s.say The black cat jumped from the green tree As far as I know, not all of its behaviour has been implemented yet (FWIW it looks like it shouldn't have returned jumped above; my guess is that it should have been climbed. Nevertheless, it seems to do that which you're looking for. Hope that helps! Cheers, Paul
Re: How to do a substring replacement in Perl 6
Thanks Bruce! On 6/8/2015 4:04 PM, Bruce Gray wrote: On Jun 8, 2015, at 3:51 PM, Douglas E. Miles d...@veritablesoftware.com wrote: Hi all! From http://perldoc.perl.org/functions/substr.html: substr has a 4th argument (or you can use substr as an lvalue) for replacement. substr EXPR,OFFSET,LENGTH,REPLACEMENT From http://doc.perl6.org/routine/substr I don't see any way to do a replacement. What is the idiomatic way of doing a positional string replacement in Perl 6? Thanks! Method form: $ perl6 -e 'my $s = abc; $s.substr-rw(1,1) = z; say $s;' azc Function form: $ perl6 -e 'my $s = abc; substr-rw($s, 1,1) = z; say $s;' azc I also do not see substr-rw in doc.perl6.org. It needs to be added. In the meantime, you can find it here: http://design.perl6.org/S32/Str.html — Hope this helps, Bruce Gray (Util of PerlMonks)