Greetings to all,
I asked in the chat window several days ago about how to accomplish this, and tye provided me a good answer using map and sort. Unfortunately, my laptop crashed shortly thereafter, and I lost his answer. (That'll teach me, ha!) However, there are a couple of complicating factors that tye may not have addressed even then, and I'm looking for wisdom on a succinct and safe way of accomplishing this.
Here's what I have:
- A file containing a tab-delimited list of words to exchange for modern spellings/equivalents, followed by a third column for any stopwords which should not have substitutions done in them.
- A file containing a list of files in which substitutions must be made.
- Over a hundred such files needing to be updated.
- The target language is Asian, where 1) there are no spaces between words; and 2) the encoding will be UTF-8. (This is significant, because any regexp must be sensitive to this, or it will fail.)
Here's an "English-ised" example of the words list file:
WORD | REPLACEMENT | STOPWORDS |
score | twenty | fourscore,scored,scores |
core | center | encore,coregent |
centre | center | |
travelled | traveled | |
hasn't | has not | |
Johann | John | Johannesburg |
So, what I need to do is substitute each word in the first column for the word(s) in the second column, except where the word in the stopwords column is matched. While this seems like a simple scenario, I'm struggling to wrap my brain around it. I'm just beginning to grasp the concepts of map and join, and their syntax, but would much appreciate some ideas for how to accomplish this.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|