By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,279 Members | 1,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,279 IT Pros & Developers. It's quick & easy.

I want to check that all characters in a word are capital or not

P: 7
This code I have written but even Good not contains all capital words like GOOD the output of my code is All word is capital which is wrong.

Can any one help me to solve this problem.

Expand|Select|Wrap|Line Numbers
  1. my $element = "Good";
  2. if ($element =~ /[A-Z]/g)
  3. {
  4.  print "All word is capital";
  5. }
  6. else
  7. {
  8. print "Not all word capital"
  9. }
Mar 6 '08 #1
Share this Question
Share on Google+
1 Reply


nithinpes
Expert 100+
P: 410
Do a complete string match. ^ stands for begining of string and $ for end of string. using /g won't server the purpose. This will tell interpreter to not stop with first search and continue further, but will not return false if pattern is not found after the first match.

Expand|Select|Wrap|Line Numbers
  1. if ($element =~ /^[A-Z]+$/)
  2. {
  3.  print "Whole word is capital";
  4. }
  5. else
  6. {
  7. print "Whole word is not capital"
  8. }
  9.  
Mar 6 '08 #2

Post your reply

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