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.