[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] poets mix problems



On Sat, Feb 26, 2000 at 10:47:17PM +0200, miku wrote:
> The idea of the program is to read in all writers' texts into one single
> string, let the user input a starting string of random length and then ha=
ve
> her/him input how many new characters in the style of the writers there a=
re
> to be produced. Then the script scans the single-line text (called
> "wholetext") for all appearances of the starting string and collects all
> letters *following* this starting string within "wholtext". Out of this s=
et
> (if it's empty, a random letter is invented) the script then chooses one
> character by random =AD a new character to output is born. Then, for the =
next
> character to be invented, the script appends the newly found character to
> the starting string and in turn trashes its first letter. So a new
> "starting" string is created. And now the seach begins anew, until the
> needed number of new characters is printed on-screen and, simultaneously,
> into a file. The result, I think, should be very funny, and - with
> increasing length of the starting string - create more and more of an
> approximation to the original texts. For instance, a starting string of
> length 4 would create a more random (and somewhat erratic or cryptic) pie=
ce
> of literature than a starting string of length 9 or 10 which would be muc=
h
> more determining.

Sounds sort of like travestry, which is in the eg/ directory of the Perl
distribution.  That one works on words, though, whereas yours will work on
characters.

MacPerl doesn't come with the eg/ directory.  You can download travesty at
<http://linguist.dartmouth.edu/~rjk/travesty>.  This is the version from
Programming Perl, 1st ed. (with one bug fix).  It will run until
terminated.


> More to the point, my problem is: if I do a pattern search, non-letter
> non-number characters like "." within the starting string might be
> interpreted as wildcards or other embedded options/commands
> (meta-characters). How can I make the search interpret its pattern as a
> plain-text string that might contain *all* 256 characters of my character
> set?

/\Q$regex/

See the documentation of quotemeta in perlfunc and \Q in perlop.


> And how can I construe and apply a mapping function that extracts all
> single characters following the starting string in "wholetext"?

@matches =3D $wholetext =3D~ /(?=3D\Q$starting_string\E(.))/gs;

I use a positive lookahead asserion, (?=3D), because the starting string ma=
y
overlap with itself.  For example, if the starting string is 'abab', and
wholetext is "XXXabababbXXX", there are two occurences of 'abab', which
happen to overlap.  The first is followed by 'a', and the second is
followed by 'b'.


Ronald

# =3D=3D=3D=3D=3D Want to unsubscribe from this list?
# =3D=3D=3D=3D=3D Send mail with body "unsubscribe" to macperl-request@macp=
erl.org