List Info

Thread: More efficient regex




More efficient regex
country flaguser name
United States
2007-02-28 11:12:52
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']+)/uL$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
Perl-Win32-Userslistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )