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

Please see Alternate between upper and lowercase, lc and uc.

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

  • 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 AnomalousMonk (Archbishop) on Jan 25, 2015 at 20:07 UTC

    I rather like one of the SO regex solutions, but without the odd-string-length problem:

    c:\@Work\Perl>perl -wMstrict -le "my $s = 'like this'; print qq{'$s'}; ;; $s =~ s{ (.)(.?) }{\U$1\L$2}xmsg; print qq{'$s'}; " 'like this' 'LiKe tHiS'


    Give a man a fish:  <%-(-(-(-<

      Odd length is only a problem if you have to change the last character. For this case we can use:
      use strict; use warnings; my $string = 'athis'; print $string =~ s/(.)(.)/$1.uc$2/egr;
      Bill