in reply to Randomly regex substitute
Yet another solution (without claiming efficiency over previous solutions)
#!/usr/bin/perl -wl use strict; my $str = "boy boy girl boy girl boy girl girl"; my $l = int(rand(rindex($str,"boy") - 1)); $str =~ s/^(.{$l}.*?)\bboy\b/$1man/; print $str;
--
Regards
- Samar
Regards
- Samar
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Randomly regex substitute
by oko1 (Deacon) on Dec 24, 2010 at 18:06 UTC |
In Section
Seekers of Perl Wisdom