Subject: | Adding title case function |
I use the same text for the title of the page (the title tags), the
header and a couple of other places. Just thought I'd offer my virtual
method:
--- CaseVMethods.pm.old 2007-02-24 21:52:07.000000000 -0700
+++ CaseVMethods.pm 2007-02-24 21:58:24.000000000 -0700
@@ -12,11 +12,14 @@
sub lowercase { lc $_[0] }
sub uppercase_first { ucfirst $_[0] }
sub lowercase_first { lcfirst $_[0] }
+sub titlecase { $_ =~ s/([\w']+)/\u\L$1/g }
@SCALAR_OPS = ( "uc" => \&uppercase,
"lc" => \&lowercase,
"ucfirst" => \&uppercase_first,
- "lcfirst" => \&lowercase_first, );
+ "lcfirst" => \&lowercase_first,
+ "titlecase" => \&titlecase,
+ );
=head1 NAME
@@ -38,6 +41,8 @@
capitalised, return the string in lower case, and return the string as
is but with the first letter lowercased.)
+Also provides a titlecase vmethod (titlecase) that uppercases the first
+letter of each word and lower cases the remainder of each word.
=head1 AUTHOR
Written by Mark Fowler E<lt>mark@twoshortplanks.comE<gt>