Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: change [A-Z] to U, [a-z] to L with one regex?

by hdb (Prior)
on Mar 19, 2013 at 11:00 UTC ( #1024260=note: print w/ replies, xml ) Need Help??


in reply to change [A-Z] to U, [a-z] to L with one regex?

tr is the one that does it:

my $r = "SomEThingWithMIXEDRegiSter"; #$r =~ tr/[A-Z][a-z]/UUUUUUUUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLLLLLL +LLL/; eval( '$r =~ tr/[A-Z][a-z]/'.('U' x 26).('L' x 26).'/' ); print $r;
The string in eval expands to the commented line above it.
For every complex problem there is an answer that is clear, simple, and wrong. H. L. Mencken


Comment on Re: change [A-Z] to U, [a-z] to L with one regex?
Download Code
Re^2: change [A-Z] to U, [a-z] to L with one regex?
by jwkrahn (Monsignor) on Mar 19, 2013 at 21:22 UTC
    #$r =~ tr/[A-Z][a-z]/UUUUUUUUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLLLLLL +LLL/; eval( '$r =~ tr/[A-Z][a-z]/'.('U' x 26).('L' x 26).'/' );

    [A-Z] is 28 characters, not 26, so your expression is wrong.

    This will work:

    $r =~ tr/A-Za-z/UUUUUUUUUUUUUUUUUUUUUUUUUUL/;
      A-Z is 28 characters, not 26,

      Since when? (Did unicrap fuck that up n'all?)


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        You have the characters [ and ] and the letters A through Z which is 28 characters.

      Thanks for your comment. I did not realize that in tr you would not need [] and that they would be treated as characters in their own right. And indeed in my script a "Z" would be translated into "L". W/o the brackets it would work. I should read the manuals more often/carefully.
      For every complex problem there is an answer that is clear, simple, and wrong. H. L. Mencken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2014-10-01 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (31 votes), past polls