473,233 Members | 1,486 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,233 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 4824
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.