Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #5031
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: Suggest a command line syntax |
| Date | 2014-12-22 21:40 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <20141222133135.43@kylheku.com> (permalink) |
| References | <m79mpq$p0h$1@speranza.aioe.org> <pg0h9a51os2c13r0vlcbphrsj1qul14hac@4ax.com> |
On 2014-12-22, Robert Wessel <robertwessel2@yahoo.com> wrote:
> On Mon, 22 Dec 2014 20:10:06 +0200, Victor Porton <porton@narod.ru>
> wrote:
>
>>I am writing a program (in fact a Perl script), which should do replacement
>>of strings in a file, like this:
>>
>>AB->BC
>>BC->AB
>>YY->ZZ
>>
>>Note that Sed and relatives fail to do this task: It would replace BC back
>>with AB after replacing AB with BC, and this is not what I need.
>
>
> Sure it will, you just need to do it a bit differently. Do the
> following:
>
> change AB -> QQQQ
> change BC -> AB
> change YY-> ZZ
> change QQQQ -> AB
>
> If "QQQQ" conflicts with another string in your source, use a
> different temporary string in the first and fourth steps.
This can be made "air tight" if it includes an extra pass which
detects whether the rename string like QQQQ occurs in the file.
while not long enough (temp_string_list ) do
do
t = generate_unique_temp_string();
while (t occurs in input file or t occurs in replacement strings)
push t onto temp_string_list
done
After this, you have enough required temp strings.
Note that you never want the temp strings to actually have a form like QQQQ.
This is because QQQQ has a suffix and a prefix which can combine to
create a spuriouis QQQQ.
If the original text contains no QQQQ, but contains QQAB, after an
AB -> QQQQ a substitution you have QQQQQQ, oops!
A brace-delimited token like {QQQQ} would be better. An insertion of {QQQQ}
cannot combine with fragments of {QQQQ} to produce a spurious {QQQQ}.
Back to comp.programming | Previous | Next — Previous in thread | Find similar | Unroll thread
Suggest a command line syntax Victor Porton <porton@narod.ru> - 2014-12-22 20:10 +0200
Re: Suggest a command line syntax Richard Heathfield <invalid@see.sig.invalid> - 2014-12-22 18:42 +0000
Re: Suggest a command line syntax Victor Porton <porton@narod.ru> - 2014-12-22 20:48 +0200
Re: Suggest a command line syntax Richard Heathfield <invalid@see.sig.invalid> - 2014-12-22 19:44 +0000
Re: Suggest a command line syntax Kaz Kylheku <kaz@kylheku.com> - 2014-12-22 20:09 +0000
Re: Suggest a command line syntax Robert Wessel <robertwessel2@yahoo.com> - 2014-12-22 14:46 -0600
Re: Suggest a command line syntax Kaz Kylheku <kaz@kylheku.com> - 2014-12-22 21:40 +0000
csiph-web