Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: uppercase/lowercase in a single expression

by McDarren (Abbot)
on Sep 07, 2006 at 06:40 UTC ( [id://571618]=note: print w/replies, xml ) Need Help??


in reply to Re^2: uppercase/lowercase in a single expression
in thread uppercase/lowercase in a single expression

Well, that's exactly what tr does.

Example:

perl -le '$line1 = "asdadAADSAsdfsfASASDjljsdASDAS"; $line1 =~ tr/[A-Z +a-z]/[a-zA-Z]/;print $line1;'
Prints:
ASDADaadsaSDFSFasasdJLJSDasdas

Replies are listed 'Best First'.
Re^4: uppercase/lowercase in a single expression
by davido (Cardinal) on Sep 07, 2006 at 07:10 UTC

    Transliteration doesn't use character classes. You don't need [ and ], unless you actually intend to also transliterate those square bracket characters. What's needed is:

    $line1 =~ tr/A-Za-z/a-zA-Z/

    ...assuming you're not dealing with some funky character set.


    Dave

      Ah, thanks for the correction. As I mentioned above, I've rarely used tr before, so it's not surprising that I got the example wrong :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-24 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found