[comp.lang.perl] uppercasing the first letter of the input

grady@fx.com (Steven Grady) (09/25/90)

Is there a better way to uppercase the first letter of the
input than the following:

    perl -pe 's/./($up = $&) =~ tr^a-z^A-Z^; $up/e'

I don't like using the extra variable.  I'd prefer:

    perl -pe 's/./$& =~ tr^a-z^A-Z^/e'

but the return value of the "tr" expression is the number of matches,
rather than the translated string itself..
-- 
	Steven
	grady@fx.com

"Once the trust goes out of a relationship, it's no fun
lying to them anymore."

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (09/25/90)

In article <1990Sep25.002313.24175@fxgrp.fx.com> grady@fx.com writes:
: Is there a better way to uppercase the first letter of the
: input than the following:
: 
:     perl -pe 's/./($up = $&) =~ tr^a-z^A-Z^; $up/e'
: 
: I don't like using the extra variable.  I'd prefer:
: 
:     perl -pe 's/./$& =~ tr^a-z^A-Z^/e'
: 
: but the return value of the "tr" expression is the number of matches,
: rather than the translated string itself..

Say

	substr($_,0,1) =~ tr/a-z/A-Z/;

Larry