Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Perl bug (was: Capitalizing words in a line.) Message-ID: <1991Feb15.153133.8849@convex.com> Date: 15 Feb 91 15:31:33 GMT References: <4861@ruuinf.cs.ruu.nl> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 42 Nntp-Posting-Host: pixel.convex.com From the keyboard of piet@cs.ruu.nl (Piet van Oostrum): :>>>>> In message , marvit@hplpm.hpl.hp.com (Peter Marvit) (PM) writes: : :PM> My own thanks to the fellow who needed to UPPERCASE certain key words in :PM> a file. It's a problem I just needed a solution for. However... : :PM> I tried doing a s|\w.|tr[a-z][A-Z]| and some variants, but nothing worked :PM> correctly. I plead to the perl community for help. : :I thought the following might be a good try: : :$_ = "this is a test case OF UPPERCASE\n"; : :s|\b(.)|$1=~tr/a-z/A-Z/|e; : :print $_ : :However, perl dumps core (segmentation fault) on this. Looks like a bug to :me (or otherwise I should get an errormessage) Yes, you can't do that (right now). The $N variables aren't really references back into the string, although I've talked a bit to Larry about it. What you have there wouldn't work anyway, as tr/// returns the number of substitutions. This works: s/\b(.)/($x = $1) =~ tr|a-z|A-Z|, $x/ge; although I'd really rather be able to do this: s/\b(.)/\u$1/g; or more precisely: s/\b([a-z])/\u$1/g; But perl doesn't support \l, \u, \L, \U, and \E. I think it would make things like this a lot easier, and probably more efficient as well. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)