Gurus,

In the sample below, I'm checking $foo for all caps or all lowercase. Is
there a more efficient regex method?

- Chris



$foo='APPLE JONES PARKER';

if(($foo!~/[A-Z]/)or($foo!~/[a-z]/)){
        $foo=&title_case($foo);
}

print $foo."\n";




sub title_case{
  my($string) = @_;
  my @exception_words = ('A', 'The', 'If', 'Is', 'It', 'Of', 'Our',
'An','On', 'In', 'But', 'With', 'Has', 'Had', 'Have');
  my @exception_stuff = ('N','S','E','W','NE','NW','SE','SW','PO','BOX');
  
  $string =~ s/([\w']+)/\u\L$1/g;
  foreach(@exception_words){$string =~ s/\b$_\b/lc($_)/ge;} # Make Exception
Words LC
  foreach(@exception_stuff){$string =~ s/\b$_\b/$_/gei;} # Make Exception
Stuff Correct Case
  
  $string =~ s/(.)/\u$1/; # Uppercase the first letter
  return $string;
}

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to