473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

problem with uppercase and lowercase:

24
hi guys,i have this problem.first let me show you the so far code

Expand|Select|Wrap|Line Numbers
  1. #!/user/bin/perl
  2. while ($a = <STDIN>)
  3. {
  4. if ($a =~ tr/A-Z/a-z/)
  5. {
  6.     print "$a\n";
  7. }
  8. if ($a =~ tr/a-z/A-Z/)
  9. {
  10.     print "the uppercase is $a\n";
  11. }
  12.  
  13. elsif ($a =~ tr/[A-Z]/[a-z]/)
  14. {
  15.     $b=$a;
  16.         $b =~ tr/A-Z/a-z/c;
  17.     print "$b\n";
  18. }
  19. }
  20.  
i got the conversion of uppercase to lowercase and vice verse,
but,the problem is i want the first letter of the output in uppercase and remaining in lowercase.
Sep 11 '07 #1
9 4832
KevinADC
4,059 Expert 2GB
You need to get familiar with all of perls builtin functions:

http://perldoc.perl.org/index-functions.html

You will find a function called 'ucfirst' in the above list of functions.
Sep 11 '07 #2
Hi

for getting the first letter in upper case or lowercase,u have to use ^

like this

$x=~s/^[A-Z]/[a-z]/;

hi guys,i have this problem.first let me show you the so far code

Expand|Select|Wrap|Line Numbers
  1. #!/user/bin/perl
  2. while ($a = <STDIN>)
  3. {
  4. if ($a =~ tr/A-Z/a-z/)
  5. {
  6.     print "$a\n";
  7. }
  8. if ($a =~ tr/a-z/A-Z/)
  9. {
  10.     print "the uppercase is $a\n";
  11. }
  12.  
  13. elsif ($a =~ tr/[A-Z]/[a-z]/)
  14. {
  15.     $b=$a;
  16.         $b =~ tr/A-Z/a-z/c;
  17.     print "$b\n";
  18. }
  19. }
  20.  
i got the conversion of uppercase to lowercase and vice verse,
but,the problem is i want the first letter of the output in uppercase and remaining in lowercase.
Sep 13 '07 #3
KevinADC
4,059 Expert 2GB
Hi

for getting the first letter in upper case or lowercase,u have to use ^

like this

$x=~s/^[A-Z]/[a-z]/;
That is not true, but it is an option that might apply to a particular situation. (Your example will convert the very first letter of a string into lower-case). But that may or may not be what humaid is trying to do. But since humaid has not replied to the question we may never know.
Sep 13 '07 #4
humaid
24
That is not true, but it is an option that might apply to a particular situation. (Your example will convert the very first letter of a string into lower-case). But that may or may not be what humaid is trying to do. But since humaid has not replied to the question we may never know.
hi guys,the problem is,suppose i give the input as,

hi this is humaid
i want the output as:Hi This Is Humaid
this is what iam trying.
Sep 14 '07 #5
numberwhun
3,509 Expert Mod 2GB
hi guys,the problem is,suppose i give the input as,

hi this is humaid
i want the output as:Hi This Is Humaid
this is what iam trying.
The following does what you want:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $phrase = "this is nobody.";
  5.  
  6. print("Unmodified phrase:  $phrase\n");
  7.  
  8. my @split_phrase = split(/\s/, $phrase);
  9.  
  10. my @new_phrase;
  11. my $var1;
  12.  
  13.  
  14. foreach my $word (@split_phrase)
  15. {
  16.     chomp($word);
  17.     $var1 = ucfirst $word;
  18.     push(@new_phrase, $var1);
  19. }
  20.  
  21. print("@new_phrase");
  22.  
Regards,

Jeff
Sep 14 '07 #6
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $phrase = "this is nobody.";
  4. $phrase =~ s/(\w+)/ucfirst($1)/eg;
  5. print $phrase;
  6.  
Sep 14 '07 #7
numberwhun
3,509 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. my $phrase = "this is nobody.";
  4. $phrase =~ s/(\w+)/ucfirst($1)/eg;
  5. print $phrase;
  6.  
Sure, one-up me. I see how you are! ;-|)

See, this is Perl. Just another example that TIMTOWTDI.

Regards,

Jeff
Sep 14 '07 #8
KevinADC
4,059 Expert 2GB
Sure, one-up me. I see how you are! ;-|)

See, this is Perl. Just another example that TIMTOWTDI.

Regards,

Jeff
naaaaa.....not one-up-manship. I wasn't going to post code but since code has been posted I figured I'd throw my 2 cents in. humaid can decide what is best for his situation.

BTW.... have you "seen" Miller lately?
Sep 14 '07 #9
numberwhun
3,509 Expert Mod 2GB
naaaaa.....not one-up-manship. I wasn't going to post code but since code has been posted I figured I'd throw my 2 cents in. humaid can decide what is best for his situation.

BTW.... have you "seen" Miller lately?
No worries, I was just bustin. Nice way of doing it. I like learning the shortcuts.

As a matter of fact, no, I have not seen our other Moderator around at all and was beginning to wonder if he has dropped off the face of the {forum|earth}. Hopefully he will apparate soon to say hello.

Regards,

Jeff
Sep 14 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner,...
8
by: Markus Dehmann | last post by:
My ios::uppercase (and others) seems not to work. #include <iostream> using namespace std; int main(){ int num = 45; cout.setf(ios::hex | ios::showbase | ios::uppercase); cout << "number " <<...
1
by: The_Kingpin | last post by:
Hi all, I need to make a function that convert a string into a certain format. Here what are the restriction: -The first letter of the first and last name must be uppercase. -If a first name...
6
by: BSHELTON | last post by:
How do I convert existing lowercase data to uppercase in Access 2000? I used the following which did not work? UPDATE HousingTowns SET tMunis=UPPER(tMunis); "HousingTowns" is the table name....
2
by: t8ntboy | last post by:
I have a table the contains field called PersonID. Each record in the personID field begins with the letter "p" in uppercase or lowercase. I want to run a query that finds all of the lowercase...
4
by: titan nyquist | last post by:
Why does ToTitleCase not work if the case is already in upper case? I have to make my string lowercase, first, before I pass to to ToTitleCase to have it work. Titan
4
by: jerger | last post by:
i have a great program now with the help of a member from this site, but i need a little customization to meet the needs of non-english speakers... who might accidendtly type punctuation which would...
7
by: tom harrison | last post by:
i'm so glad i found this forum! i have to have some coursework done by the end of the week and i really need it explaining to me. i'm not really that big on stuff like this but it's a part of my web...
4
by: cpptutor2000 | last post by:
Could some C guru provide some hints on my problem? I am trying to sort an array of character strings, where each string contains lowercase, uppercase, digits as well as non-alphanumeric characters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.