Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: uppercase/lowercase in a single expression

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


in reply to uppercase/lowercase in a single expression

You need the uc (upercase) and lc (lowercase) functions, and a conditional statement such as "if".

This smells a bit like homework, so I'll leave you to work the rest out for yourself.

Update: actually, you're probably better off with the transliteration operator (tr). This one didn't occur to me straight off as I rarely use it myself. See perlop for details. Also, if you want to edit the file without opening it, then you'll be interested in the 'i' and 'p' command line switches - see perlrun for details on these.

  • Comment on Re: uppercase/lowercase in a single expression

Replies are listed 'Best First'.
Re^2: uppercase/lowercase in a single expression
by greatshots (Pilgrim) on Sep 07, 2006 at 06:33 UTC
    McDarren

    $line1 = 'asdadAADSAsdfsfASASDjljsdASDAS'; $line2 = 'GKHSKJADHasdadhkadhGHKJHKJHasdada';
    do you mean to say that should I need traverse each character and change it to upper/lower ?

      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

        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

      thanks a lot.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-23 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found