in reply to Re: Pattern Matching, left-to-right
in thread Pattern Matching, left-to-right
If you had tested it with more input, you'd have found it is wrong.
You wrote:
foreach my $key (keys %convs) { $in =~ s/$convs{$key}/$key/g; }
The OP wrote:
And that *almost* works perfectly. Where it doesn't work is if there's two of these special characters grouped around a normal character... [...] And since I can get these in any order, there's no way to put them in an order that always works.
Since you stored the patterns as values in a hash, the order in which they're substituted gets randomized such that with the input you tested with, the code happens to work.
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Pattern Matching, left-to-right
by Prior Nacre V (Hermit) on Aug 21, 2004 at 14:54 UTC | |
by Aristotle (Chancellor) on Aug 21, 2004 at 15:09 UTC | |
by Prior Nacre V (Hermit) on Aug 21, 2004 at 15:29 UTC |