Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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/


Comment on Re: How to use \l and \u in regex mathing patterns?
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969663]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-12-28 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls