in reply to Print the string out in alternating upper and lowercase letters LiKe tHiS.

"LiKe tHiS" is NOT alternating upper and lowercase letters, there is a lower case "e" followed by a lower case "t". Or is there an upper case blank inbetween?

  • Comment on Re: Print the string out in alternating upper and lowercase letters LiKe tHiS.

Replies are listed 'Best First'.
Re^2: Print the string out in alternating upper and lowercase letters lIkE ThIs
by Discipulus (Canon) on Jan 26, 2015 at 12:43 UTC

    perl -e "print map { $c++ %2 ? chr $_^' ' : chr $_ } unpack 'C*', $ARG +V[0]" "like this"
    suffers the same problem of whitespace but is less redable... ;=)

    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^2: Print the string out in alternating upper and lowercase letters LiKe tHiS.
by Anonymous Monk on Jan 26, 2015 at 13:22 UTC
    A more robust solution if you like:
    perl -CO -Mutf8 -E 'say map { /\P{Cased}/ ? $_ : $c++ % 2 ? lc : uc } "comme ça" =~ /(\X)/g'
    Of course, at this point we should perhaps consider ucfirst and fc...
      (a typo; /^\P{Cased}/, of course, or else it can find these annoying combining marks...)