my $N = 1; # Number of replacements. my $a = "boy boy girl boy girl boy girl girl"; my @b = split ' ', $a; my $c = grep {$_ eq "boy"} @b; my @d = map {$_ eq "boy" && rand($c--) < $N ? do {$N--; "man"} : $_} @ +b; say "@d";
In reply to Re: Randomly regex substitute
by JavaFan
in thread Randomly regex substitute
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |