Hi, I have finally written my first real script. It is just a basic "Tell-a-friend" about a site script. But I have run into two issues:

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

In reply to making first letter of all words in array upper case by iamrobj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.