Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] substitution + backreferences + function call

Expand Messages
  • merlyn@stonehenge.com
    ... da5id but when I try to use: da5id s/ b($keyword) b/uc $1/gi; da5id I m getting a literal uc rather than the results of the function. Any da5id
    Message 1 of 3 , Apr 15 7:02 AM
    • 0 Attachment
      >>>>> "da5id" == da5id <da5id@...> writes:

      da5id> but when I try to use:
      da5id> s/\b($keyword)\b/uc $1/gi;

      da5id> I'm getting a literal "uc" rather than the results of the function. Any
      da5id> suggestions - is my approach a sound one?

      Well, for "uc" specifically, you can use \U:

      s/\b($keyword)\b/\U$1/gi;

      But in general, you can use /e, as in:

      s/\b($keyword)\b/uc $1/gie;

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    • da5id
      ... Very cool - I like the option of using e as a regex evaluation option since I can envision myself needing to evaluate a lot as I do the substitution. I
      Message 2 of 3 , Apr 15 7:15 PM
      • 0 Attachment
        > you can use \U: s/\b($keyword)\b/\U$1/gi;

        Very cool - I like the option of using e as a regex evaluation option
        since I can envision myself needing to evaluate a lot as I do the
        substitution. I looked in the Llama book and didn't see this but then
        found a reference in Freidl's Mastering Regular Expressions although it
        missed a complete list. He called it a Case-Folding Span. Are \1 and \U
        the only ones of these?

        Thanks much,

        David


        Randal L. Schwartz wrote:
        >>>>>> "da5id" == da5id <da5id@...> writes:
        >>>>>>
        >
        > da5id> but when I try to use:
        > da5id> s/\b($keyword)\b/uc $1/gi;
        >
        > da5id> I'm getting a literal "uc" rather than the results of the function. Any
        > da5id> suggestions - is my approach a sound one?
        >
        > Well, for "uc" specifically, you can use \U:
        >
        > s/\b($keyword)\b/\U$1/gi;
        >
        > But in general, you can use /e, as in:
        >
        > s/\b($keyword)\b/uc $1/gie;
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.