Kenin has asked for the wisdom of the Perl Monks concerning the following question:
1. I am trying to form a sequence with letter DA of width 100..
2. I want to restrict the occurrence of 'DA' in this 100(characters) to 20%, 30% and so on...
i.e
There are 3 DA's in the string...DADADDDADDD
I want to have control on occurrence of DA and generate sequence randomly for 100 characters
But i am not able to have control on the occurrence of 'DA'#!/usr/local/bin/perl my @chars = ('A','D',); my $string = join '', map $chars[ rand @chars ], 1 .. 100; while ($string =~ /DA/g) { $count++ } print "There are $count DA's in the string \n "; print $string ;
It keeps changing randomly with this coding
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding a pattern in a string
by FunkyMonk (Bishop) on Oct 27, 2007 at 08:10 UTC | |
|
Re: Finding a pattern in a string
by deorth (Scribe) on Oct 27, 2007 at 07:58 UTC | |
|
Re: Finding a pattern in a string
by GrandFather (Saint) on Oct 27, 2007 at 08:03 UTC | |
by blazar (Canon) on Oct 27, 2007 at 12:34 UTC | |
|
Re: Finding a pattern in a string
by deorth (Scribe) on Oct 27, 2007 at 08:14 UTC | |
by Gavin (Archbishop) on Oct 27, 2007 at 17:25 UTC | |
|
Re: Finding a pattern in a string
by Anonymous Monk on Oct 27, 2007 at 07:47 UTC |