Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: How to use \l and \u in regex mathing patterns?

by brx (Pilgrim)
on May 09, 2012 at 16:45 UTC ( #969663=note: print w/replies, xml ) Need Help??

in reply to How to use \l and \u in regex mathing patterns?

$ perl -e '$b="H";( $a = "hello" ) =~ s/^\l$b/Y/; print $a' Yello

see perlre: \l   lowercase next char

So, after interpolation, "\l$b" gives "\lH" ie "h" and you obtain s/h/Y/

Replies are listed 'Best First'.
Re^2: How to use \l and \u in regex mathing patterns?
by Anonymous Monk on May 09, 2012 at 16:54 UTC
    What an ugly hack.

    If someone asks "How do I X with Y?", and you recognise that Y is a particularly bad way to accomplish X, then you are supposed to answer with the better way Z. If taking the question at face value, at least mention the caveats of Y.

      I don't think it was a hack, ugly or otherwise. I think it was intended, and succeeds, as an example of the actual way interpolation control operators can work in a regex, which was the context of the original – albeit misguided, since pat_mc thought of them as character classes – question. (Although I must admit that, had I given the example myself, I might have mentioned that those operators are rarely used in that particular way.)

      If someone asks ...

      Somebody already gave that answer

      ... then you are supposed to ...
      No, you are not.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969663]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2018-05-28 08:17 GMT
Find Nodes?
    Voting Booth?