CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Need to Change Case from All CAPs to Normal Capitalize

 



jmmorse
Novice

Apr 30, 2002, 11:47 AM

Post #1 of 8 (3230 views)
Need to Change Case from All CAPs to Normal Capitalize Can't Post

I have a website complete with an Auction and I am tired of the people placing auctions in

*** ALL CAPITAL LETTERS ***

I would like to be able to change the "title" or "subject" of the users post to "Capitalize Sentences" and prevent the user from using all Caps.

Does anyone know of a program for this, or sometype of code that I can add to the script that will solve my problem?

Thanks!
~John


fashimpaur
User

May 2, 2002, 6:24 AM

Post #2 of 8 (3227 views)
Re: [jmmorse] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

jmmorse,

I made a little method for you that should fix this problem:

Code
  

$title
= "THE QUICK BROWN FOX";

$subject = "A LITTLE STORY ABOUT A FOX. THE LAZY DOG IS JUST AN EXTRA.";

$test3 = "A goofy MIXED Case SenTence. And One Without A Period";

$test4 = "A normal sentence is here. IT IS FOLLOWED BY AN ALL CAPS SENTENCE!";



sub sentenceCase {

my $input = shift;
my $output = "";
$input =~ s/\b([^\.]+)/ucfirst(lc($&))/eg;
return $input;

}


print sentenceCase($title),"\n";
print sentenceCase($subject),"\n";
print sentenceCase($test3),"\n";
print sentenceCase($test4),"\n";

HTH,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


uri
Thaumaturge

May 4, 2002, 1:43 AM

Post #3 of 8 (3219 views)
Re: [fashimpaur] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

$input =~ s/\b([^\.]+)/ucfirst(lc($&))/eg;

better to do that as:

$input =~ s/\b([^\.]+)/\u\L$1/g;

in double quotish strings \u is ucfirst and \L is lc
and by using those you don't need the /e modifier

and don't use $& which is bad as it slows down all
s/// operations by forcing a copy.


jmmorse
Novice

May 4, 2002, 8:51 AM

Post #4 of 8 (3215 views)
Re: [uri] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

that script works great... However I can't figure out how to add it to my Auction so that it will do the trick.

Here is the code I'm working with:


Code
  

# Sub: Post New Item
sub new2 {
my ($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids);
if ($form{'REPOST'}) {
$form{'REPOST'} =~ s/\W//g;
if (-T "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat") {
open THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat";
($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = <THEFILE>;
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids);
$title =~ s/\"//g; # quotes cause problems for a text input field, However this does not seem to work.
}}



print <<"EOF";
<table width=95% cellspacing=0 cellpadding=0 border=0 bgcolor=$config{'colortablehead'}>
<tr><td width="100%" align=center><font size=5 color=$config{'colorheadtext'}><b>Post Item For Bids</font></b></td></tr>
</table>
EOF
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=procnew>";
print "<tr><td align=center width=100% BGCOLOR=$config{'colortablebody'}><br></td></tr>";
print "</table>";
print "</tr></table>";
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<tr>";
print "<td BGCOLOR=$config{'colortablebody'} width=38%><b>\&nbsp\;Select Category:</b></td>";
print "<td align=left BGCOLOR=$config{'colortablebody'} width=62%>";
print "<SELECT NAME=CATEGORY style=\"background-color: #FFFFFF\; color:maroon\">";
print "<OPTION SELECTED>Select Category</OPTION>";
my $key;
foreach $key (sort keys %searchcats) {
@cat = split(/ - /,$searchcats{$key});
if ($cat[1] ne "") {
print "<OPTION VALUE=$key>$searchcats{$key}</OPTION>\n" if ($searchcats{$key} ne " - ");
}}
print "</SELECT></TD></TR></table>";
print <<"EOF";
<br><table align="center" bgcolor="white" bordercolor="red" border="1" cellspacing="0" cellpadding="0" width=98%>
<tr>
<td align=center><TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP><font face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000" size="3"> Please <u><b>Do Not Use</b></u> Special Characters, Html,<br><b>ALL CAPITALS</b>, or Excessive Spacing ! </font></TD></TR>
</TABLE>
<TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP>\&nbsp\;<B>Title/Item Name:</B></TD><TD><INPUT NAME=TITLE VALUE=\"$title\" TYPE=TEXT SIZE=50 MAXLENGTH=50 style="text-transform: Capitalize"></TD></TR>
</table></td>
</tr>
</table>



jmmorse
Novice

May 6, 2002, 9:31 AM

Post #5 of 8 (3205 views)
Re: [jmmorse] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

Anybody ? Please ? I really need help on this.

thanks

~John


fashimpaur
User

May 7, 2002, 5:02 AM

Post #6 of 8 (3197 views)
Re: [jmmorse] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

jmmorse,

The problem, I think, is how you are reading in from the file:

My suggestions are as follows (assuming you are going to leave the
function named sentenceCase()):


change this line:

($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = <THEFILE>;

to this:

($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = map{sentenceCase($_)} <THEFILE>;

I tested this locally with dummy data for the input and it works just fine. Let me know if you have anymore problems.

Good Luck,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


jmmorse
Novice

May 7, 2002, 9:03 AM

Post #7 of 8 (3195 views)
Re: [fashimpaur] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

First of all, I really do appreciate the help you guys are giving me on this! But, I still could not get this to work. I changed the script from this:


Code
  

# Sub: Post New Item
sub new2 {
my ($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids);
if ($form{'REPOST'}) {
$form{'REPOST'} =~ s/\W//g;
if (-T "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat") {
open THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat";
($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = <THEFILE>;
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids);
$title =~ s/\"//g; # quotes cause problems for a text input field, However this does not seem to work.
}}



print <<"EOF";
<table width=95% cellspacing=0 cellpadding=0 border=0 bgcolor=$config{'colortablehead'}>
<tr><td width="100%" align=center><font size=5 color=$config{'colorheadtext'}><b>Post Item For Bids</font></b></td></tr>
</table>
EOF
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=procnew>";
print "<tr><td align=center width=100% BGCOLOR=$config{'colortablebody'}><br></td></tr>";
print "</table>";
print "</tr></table>";
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<tr>";
print "<td BGCOLOR=$config{'colortablebody'} width=38%><b>\&nbsp\;Select Category:</b></td>";
print "<td align=left BGCOLOR=$config{'colortablebody'} width=62%>";
print "<SELECT NAME=CATEGORY>";
print "<OPTION SELECTED>Select Category</OPTION>";
my $key;
foreach $key (sort keys %searchcats) {
@cat = split(/ - /,$searchcats{$key});
if ($cat[1] ne "") {
print "<OPTION VALUE=$key>$searchcats{$key}</OPTION>\n" if ($searchcats{$key} ne " - ");
}}
print "</SELECT></TD></TR></table>";
print <<"EOF";
<br><table align="center" bgcolor="white" bordercolor="red" border="1" cellspacing="0" cellpadding="0" width=98%>
<tr>
<td align=center><TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP><font face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000" size="3"> Please <u><b>Do Not Use</b></u> Special Characters, Html,<br><b>ALL CAPITALS</b>, or Excessive Spacing ! </font></TD></TR>
</TABLE>
<TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP>\&nbsp\;<B>Title/Item Name:</B></TD><TD><INPUT NAME=TITLE VALUE=\"$title\" TYPE=TEXT SIZE=50 MAXLENGTH=50 style="text-transform: Capitalize"></TD></TR>
</table>



To This:


Code
  

# Sub: Post New Item
sub new2 {
my ($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = map{sentenceCase($_)} <THEFILE>;
if ($form{'REPOST'}) {
$form{'REPOST'} =~ s/\W//g;
if (-T "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat") {
open THEFILE, "$config{'basepath'}$config{'closedir'}/$form{'REPOST'}.dat";
($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = map{sentenceCase($_)} <THEFILE>;
close THEFILE;
chomp($title, $reserve, $inc, $desc, $image, $imagea, $imageb, $imagec, $imaged, $imagee, $imagef, $imageg, $imageh, $imagei, $payment, $shipping, $condition, $feat, $paws, $grabber, $bold, $dutch, $qty, $silent, $relister, $buyit, $buyitnow, @bids) = map{sentenceCase($_)} <THEFILE>;
$title =~ s/\"//g; # quotes cause problems for a text input field, However this does not seem to work.
sub sentenceCase {

my $input = shift;
my $output = "";
$input =~ s/\b([^\.]+)/\u\L$1/g;
return $input;

}
}}

print <<"EOF";
<table width=95% cellspacing=0 cellpadding=0 border=0 bgcolor=$config{'colortablehead'}>
<tr><td width="100%" align=center><font size=5 color=$config{'colorheadtext'}><b>Post Item For Bids</font></b></td></tr>
</table>
EOF
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<FORM ACTION=$ENV{'SCRIPT_NAME'} METHOD=POST>";
print "<INPUT TYPE=HIDDEN NAME=action VALUE=procnew>";
print "<tr><td align=center width=100% BGCOLOR=$config{'colortablebody'}><br></td></tr>";
print "</table>";
print "</tr></table>";
print "<TABLE width=95% BORDER=0 CELLSPACING=0 CELLPADDING=0>";
print "<tr>";
print "<td BGCOLOR=$config{'colortablebody'} width=38%><b>\&nbsp\;Select Category:</b></td>";
print "<td align=left BGCOLOR=$config{'colortablebody'} width=62%>";
print "<SELECT NAME=CATEGORY>";
print "<OPTION SELECTED>Select Category</OPTION>";
my $key;
foreach $key (sort keys %searchcats) {
@cat = split(/ - /,$searchcats{$key});
if ($cat[1] ne "") {
print "<OPTION VALUE=$key>$searchcats{$key}</OPTION>\n" if ($searchcats{$key} ne " - ");
}}
print "</SELECT></TD></TR></table>";
print <<"EOF";
<br><table align="center" bgcolor="white" bordercolor="red" border="1" cellspacing="0" cellpadding="0" width=98%>
<tr>
<td align=center><TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP><font face="Verdana, Arial, Helvetica, sans-serif" color="#FF0000" size="3"> Please <u><b>Do Not Use</b></u> Special Characters, Html,<br><b>ALL CAPITALS</b>, or Excessive Spacing ! </font></TD></TR>
</TABLE>
<TABLE align=center BORDER=0 CELLSPACING=0 CELLPADDING=0>
<TR><TD align=center VALIGN=TOP>\&nbsp\;<B>Title/Item Name:</B></TD><TD><INPUT NAME=TITLE VALUE=\"$title\" TYPE=TEXT SIZE=50 MAXLENGTH=50 style="text-transform: Capitalize"></TD></TR>
</table></td>
</tr>
</table><br>
<table border="0" width=95% cellspacing="0" cellpadding="0" BGCOLOR=$config{'colortablebody'}>
<tr><td width="100%" align="left"><b>Attention Grabber <font color="#FF0000">\$$config{'grabberfee'} Fee</font></b></td></tr>
</table>



jmmorse
Novice

May 7, 2002, 9:07 AM

Post #8 of 8 (3194 views)
Re: [jmmorse] Need to Change Case from All CAPs to Normal Capitalize [In reply to] Can't Post

I'm going to try to attach the cgi files so that it will be easier to read.

thank-you sooo much!
Attachments: postitem_w_changes.cgi (49.0 KB)
  postitem.cgi (48.8 KB)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives