LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-20-2006, 02:04 PM   #1
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Rep: Reputation: 15
Capitalize inputs


Is there a way you can capitalize the inputs of a string in the perl language?
 
Old 09-20-2006, 02:14 PM   #2
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Is this what you're looking for?
Code:
ada@barnabas:~> perl -e 'print uc( "upper case" ), "\n";'
UPPER CASE
 
Old 09-20-2006, 02:42 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

Or this? ... cheers, makyo
Code:
% perl -e ' print join(" ", map { ucfirst } split(" ", "my dog has fleas")), "\n";'
My Dog Has Fleas
 
Old 09-20-2006, 02:52 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Here's another...
Code:
perl -pi.bak -e 's/(\w+)/\u\L$1/g' file.txt
 
Old 09-20-2006, 03:05 PM   #5
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
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
 
Old 09-20-2006, 03:21 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Can't you use 'i' command to ignore case
Code:
if ($x =~ /y/i)
 
Old 09-22-2006, 01:17 AM   #7
circuit_girl
Member
 
Registered: Sep 2006
Posts: 35

Original Poster
Rep: Reputation: 15
how does that i command work I never heard of it.
 
Old 09-22-2006, 10:24 AM   #8
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
Hi.

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
 
Old 09-22-2006, 10:52 AM   #9
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
It's very easy with Bash.

Code:
#!/bin/bash

echo "What's your name?"
read NAME 

echo $NAME | tr a-z A-Z
 
  


Reply

Tags
case, perl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using mencoder with composite inputs Caysho Linux - Software 1 01-24-2006 03:01 AM
auto capitalize after quotes AnimaSola Linux - Software 3 12-06-2005 10:39 PM
Capitalize folders with less than 4 characters bendeco13 Linux - General 9 10-07-2005 05:04 AM
Javascript and Radio Inputs. swatward Programming 1 05-06-2005 04:51 AM
MythTV claims all my inputs are in use. None actually are Pcghost Linux - Software 2 03-24-2005 10:42 AM


All times are GMT -5. The time now is 12:16 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration