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

[MacPerl] poets mix problems



Hi all Perl beginners!

I=3DB9m still at some point in the process of beginning to lear (Mac)Perl. =
My
impression of the participants of this list =3DAD so far =3DAD has been tha=
t th=3D
ere
are a lot of MacPerl experts who deliberately share their ideas and
approaches to solving sophisticated Perl problems.

Now I could also need some inter-personal support regarding more basic
issues, for instance: how to set up regular expressions, how to create
variables at runtime (one approach would include the use of "eval", I
think), how to set up and address multidimensional arrays, how to employ
slices of arrays, hash processing and so forth. And: I could need some
playful input in terms of "fun".

For example, I have just begun to write a Perl script that takes a couple o=
=3D
f
literary texts (such as written by Shakespeare, Marx, and W. Whitman...) an=
=3D
d
"mixes" them so that its output is a new, kind-of random text in the style
of the "processed" poets. It should also be possible to "mix" only one
single file, and the resulting output would be another piece of prose or
"poetry" in the style of the respective author.

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 have
her/him input how many new characters in the style of the writers there are
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 set
(if it's empty, a random letter is invented) the script then chooses one
character by random =3DAD a new character to output is born. Then, for the =
ne=3D
xt
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) piece
of literature than a starting string of length 9 or 10 which would be much
more determining.

So far I=3DB9ve not only sketched the algorhythm but also programmed the sc=
ri=3D
pt
so that it does what it is supposed to do. But reading in, say, about
300.000 characters into one string and then search again and again and
again... is highly (und understandably) slow yet, even on a G3 with 233 Mhz=
=3D
.
Even more so as I plan to read in the complete works of William Shakespeare
(from a CD rom, amounting to a string consisting of roughly 24 million
bytes)... The problem: the script is going through "wholetext" *letter by
letter* as I lack some fundamental understanding of regular expressions
which would make searching it much faster, I imagine. And it would be nice
if I could write a kind of "mapping" construct that subsequently extracts
the respective following characters out of "wholetext" into one collective
string.

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? And how can I construe and apply a mapping function that extracts all
single characters following the starting string in "wholetext"? And, for
future expansion: assuming a unicode input: how to deal with, for example,
the large variety of Chinese characters? In which ways would the script
probably have to be adapted?

All this is to show that a) I could need your help and b) maybe I'm not
alone here with very basic questions about the specialties of Perl that mak=
=3D
e
this language so fascinating. I would like to invite you to share your idea=
=3D
s
for solutions as well as to present "simple" problems of your own.

Michael


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



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