-   Programming (
-   -   Capitalize inputs (

circuit_girl 09-20-2006 03:04 PM

Capitalize inputs
Is there a way you can capitalize the inputs of a string in the perl language?

spirit receiver 09-20-2006 03:14 PM

Is this what you're looking for?

ada@barnabas:~> perl -e 'print uc( "upper case" ), "\n";'

makyo 09-20-2006 03:42 PM


Or this? ... cheers, makyo

% perl -e ' print join(" ", map { ucfirst } split(" ", "my dog has fleas")), "\n";'
My Dog Has Fleas

homey 09-20-2006 03:52 PM

Here's another...

perl -pi.bak -e 's/(\w+)/\u\L$1/g' file.txt

circuit_girl 09-20-2006 04:05 PM

I need to capitilize the input from the users input from a question my program asks and I am going to write conditional programming for it and I thought it would be easier to write one compare statement instead of two, cause of the case sensitivity.

for instance if the user types y I want to change it to Y so I do not have to test for lower and upper case character through out my program.

Thank you

homey 09-20-2006 04:21 PM

Can't you use 'i' command to ignore case

if ($x =~ /y/i)

circuit_girl 09-22-2006 02:17 AM

how does that i command work I never heard of it.

makyo 09-22-2006 11:24 AM


The "i", along with a few other characters, are usually called modifiers because they change the way the matching works. This one causes case to be ignored ... cheers, makyo

X.Cyclop 09-22-2006 11:52 AM

It's very easy with Bash.:D



echo "What's your name?"
read NAME

echo $NAME | tr a-z A-Z


All times are GMT -5. The time now is 11:06 AM.