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

    Thanks - fixed - see update.

    Regards,

    PN5

      Of course, that's exactly the same as the solutions by antirice and by ysth.. :-)

      Makeshifts last the longest.

        Yes, a strange wave of déjà vu did waft in my general direction when I rewrote those bits. Now I know why :-)

        Update: Yet Another Version :-)

        Regards,

        PN5