in reply to Re: Regex Substitution Evaluations
in thread Regex Substitution Evaluations

Please refer to my original post.

As you can see, I would absolutely like to avoid using eval, and I have consulted perldoc's perlre perlop perlretut and perlreref entries several times.

How might you suggest going about substitutions?

Replies are listed 'Best First'.
Re^3: Regex Substitution Evaluations
by Your Mother (Archbishop) on Jul 05, 2008 at 20:51 UTC

    I think pc88mxer answered your question for the most part.

    $my_name = replace("august ferdinand mobius","\b(\w)","\U$1","igs"); # Becomes something more like... $my_name = replace("august ferdinand mobius", qr/(?igs)\b(\w)/, '\U$1' +);

    Update: You should consider that your solution will not work for a variety of names, like mccleod, vomdorp, decaro, etc. For proper names, a dictionary (with the right library under it, like proper names) is a better way to go, and there is no perfect solution since the same spellings are sometimes capitalized differently. :(

      I gave a few examples, more-or-less off the top of my head, in an article I wrote a number of years ago, when I was talking about the inadvisability of assumptions when it came to names:

      John deJongh
      Jan M. van de Geijn
      Kathleen O'Hara-Mears
      Siu Tim Au Yeung
      Nang-Soa-Anee Bongoj Niratpattanasai
      Mjölby J. de Waærn
      

      Also, assuming things about the order of, say, Chinese or Indian names is likely to run into problems - even within a given city, in the latter case.

      
      -- 
      Human history becomes more and more a race between education and catastrophe. -- HG Wells
      
      The names problem is interesting, although I'm sort of kicking myself for giving it as an example. The motivation for this post was and is to develop a general substitution framework for parametrized regex creation...