in reply to Finding a random position within a long string (Activeperl Build 822)
Seems straight forward enough...
my $string = 'ABC' x 1_000_000; $string =~ s/(.)/( rand 10 < 1 ) ? '?' : $1/eg; print $string;
I get: ABCABC?BC?BCABCABCABCA?CABCABCABCABCA?CABCABCABCABCAB?ABCABCABCABCABCABCABCABCA...
It's easy enough that I wonder if I'm misunderstanding your question.
Update: The full output has 298993 question marks and 2701007 other characters, but of course that varies with every execution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding a random position within a long string (Activeperl Build 822)
by lodin (Hermit) on Oct 12, 2007 at 23:57 UTC | |
|
Re^2: Finding a random position within a long string (Activeperl Build 822)
by mwah (Hermit) on Oct 12, 2007 at 21:40 UTC |