in reply to Reversing Arabic String direction

I think it can be done more elegantly, but this works for me

DB<112> $str ="a123bc45de" => "a123bc45de" DB<113> join "", reverse map { /\d/ ? $_ : scalar reverse $_ } split + /(\d+)/, $str => "ed45cb123a"

HTH! :)

edit

Cheers Rolf

(addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Reversing Arabic String direction
by boftx (Deacon) on Jul 10, 2014 at 21:56 UTC

    The question I had was how to handle things like "name21" or even "name_21". Both yours and my "solutions" have a problem with words like that. AppleFritter is on the right track, but I think this is the key consideration that will cause the most headaches.

    You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
      nope IMHO thats the way it should be in Arabic, if numbers were reversed:

      DB<115> join "", reverse map { /\d/ ? $_ : scalar reverse $_ } split + /(\d+)/, name_21 => "21_eman"

      But I didn't check your code...

      Cheers Rolf

      (addicted to the Perl Programming Language)

        Like I said, I took a brute-force approach. I'm not surprised at all (and expected) that a better, cleaner way would be apparent to one such as yourself. :)

        The code I provided will produce "21_eman" when given "name_21" as input. I think yours does the same (but I didn't test yours.) I have no idea what the correct way of dealing with that is.

        You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.