in reply to Golf - now for the Sentencing.

Of course, the real-world case is not this simple. So? ;-)

I include a simple test harness, but otherwise follow your lead -- up to and including that trailing ";", with which my solution comes in at 25 strokes:

# Test: $_='there is more than one way to do it. beware sentences followed by anything other than a single " ". just another golfer.'; # 3456789 123456789 12345 s/^.|\bi\b|\.\s*./\U$&/g; # Proof: print;

The Sidhekin
print "Just another Perl ${\(trickster and hacker)},"

Replies are listed 'Best First'.
Re: Re: Golf - now for the Sentencing.
by redsquirrel (Hermit) on Apr 22, 2002 at 13:20 UTC
    But this solution doesn't work when
    $_='tHere are CAPITAL leTters iNterSpersed';
    I believe grep wants everything to be lowercased other than beginning of sentences and single I's. Adding an lc and using your regex, this code
    # Test: $_='tHere is more than one way to do it. Also, i am just ANOTHER golfer.'; # 1 2 3 #234567890123456789012345678901 $_=lc;s;^.|\bi\b|\.\s*.;\U$&;g; # Proof print
    should output this
    There is more than one way to do it. Also, I am just another golfer.

      I believe grep wants everything to be lowercased other than beginning of sentences and single I's.

      Well, that's what I get for reading the rules only, and not his solution. Clearly, the intent of that code is to lowercase everything else. I cannot beat 31, and nor does japhy — his code is identical to yours, except for your trailing ";" and variant delimiters (and if he can ignore the test harness, so can you).

      (But I would have found the same! :-)

      Now, of course the lc version is shorter and therefore better, but I could not leave this without some code, now could I? This is at 35 strokes; the best remains at 31.

      # 3456789 123456789 123456789 12345 s/(^.|\.\s*.|\bi\b)|(.)/\U$1\L$2/g;

      The Sidhekin
      print "Just another Perl ${\(trickster and hacker)},"