Just another Perl shrine | |
PerlMonks |
Re: String replaceby benizi (Hermit) |
on Nov 29, 2005 at 23:10 UTC ( [id://512795]=note: print w/replies, xml ) | Need Help?? |
General idea: Grab the unique IN CAPITALS words from a line. For each IN CAPS, choose a distinct random product. Replace each IN CAPS with its product. My choose-random-set-with-no-dupes algorithm:
I'm not sure how this algorithm stacks up against the "keep picking randomly until I get one I haven't already picked" algorithm. I'm guessing if @random_items >> $number_to_choose, it's not going to make much difference. Here's the final code. Note that I took your example of "set IN CAPITALS quite helpfully" to mean that products can contain spaces. (See FROSTED FLAKES example).
In Section
Seekers of Perl Wisdom
|
|