iamrobj has asked for the wisdom of the Perl Monks concerning the following question:
1. I want to read the name of the person sending the referral to be read into an array, and then uppercase the first character of every word entered.
2. I have given a textarea for the user to enter an additional message to their friend. I have managed to set it up so that if there is no ".", "?" or "!" at the end of the message, a "." will be added. BUT, if there are 4 !!!!'s at the end, or ?!?, !?!, .!., !.!, ??? etc., a period is still put it?
But a period is NOT put in with these combinations:
?!, !?, !., .!, ?., .?,
It only seems to happen with a combination of three !'s, ?'s or .'s.
Wanting to ormat the extra message is only a result of my quest for perfection, and this often slows me down, but it would be nice to have the first letters of the names in uppercase :)
What am I doing wrong?
#!/usr/bin/perl -wT ################################ ################################ ### ### ### written by Rob Johnson ### ### www.robj.ca ### ### tellscript@robj.ca ### ### ### ################################ ################################ use CGI::Carp qw(fatalsToBrowser); use strict; use CGI ':standard'; # fixes the error with -t switch in mailprogram line? # hey I don't know... but it works! :) $ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin"; my $redirect = "http://www.robj.ca/told.htm"; my $sitename = "robj.ca"; my $siteurl = "http://www.robj.ca"; my $from = param('from'); my $to = param('to'); my $frommail = param('frommail'); my $tomail = param('tomail'); my $message = param('message'); # make the first letter of the names upper case my @from = split(/\? ?/, $from); # I was trying to use a "space" as the split character in the above li +ne!! # split(/\? ?/, $from) ????????? :( # now I want to make the first letter of every word in the array, uppe +rcase! foreach (@from) { @from = ucfirst($from); } # this makes the first word upper case... $to = ucfirst($to); # make the first letter of the message upper case $message = ucfirst($message); ############################################## # puts a period at the end of senders message, # if one was not there, AND, if there is no # question OR explanation mark. my $length = length($message); my $period = index($message, "."); my $question = index($message, "?"); my $explanation = index($message, "!"); $length = $length - 1; if (($period ne $length) && ($question ne $length) && ($explanation ne + $length)) { $message = $message.'.'; } ############################################## # sending mail now... open (MAIL, "|/usr/sbin/sendmail -t") || Error ('open', 'mail program' +); print MAIL "From: $frommail\n"; print MAIL "To: $tomail\n"; print MAIL "Subject: $to, @from says check out $sitename!\n\n"; print MAIL "This is NOT spam! You were sent the email by @from ($fro +mmail),\nat IP: $ENV{'REMOTE_ADDR'}\n\n\n"; print MAIL "Hello $to, @from has sent you this email inviting you to + check out $siteurl\n\n\n"; print MAIL "@from also had this to say:\n$message\n\n\n" if ($messag +e ne ""); print MAIL "So check out $siteurl!"; close (MAIL); sub Error { print "The server can't $_[0] the $_[1]: $! \n"; exit; } # ready browser for html output print "Content-type: text/html\n\n"; # redirect the browser... print "<meta http-equiv=\"refresh\" content=\"0;url=$redirect\">"; # end
|
|---|