Well, first of all, an observation: how is the user meant to know how to separate multiple friends? Further, how are they even meant to know that you actually can send the message to multiple friends? I know you've written "friends", but I think you really mean either "friend's" or "friends'", but anyway, enough of this English pedantry. Also, this way of entering friend information is highly error prone: the names and e-mail address could easily get out of sync (e.g. what if the user enters 3 friend names, but only two e-mail addresses?)

Generally, you've got the right idea, but you just seem a bit confused about Perl syntax. In your code, you are doing @from = ucfirst($from). What you're doing is effectively wiping out the array (as you're assigning to @from with the initial-uppercased version of the first element. You probably want to do something like this instead:

my @friends = split / /, $raw_friends; # space in split() is fine $_ = ucfirst for @friends;
Note the $_ = ucfirst for @friends code: it loops through the @friends array, assigning each element in turn to the $_ variable. We are overwriting that variable with the uppercased version of it (like many Perl built-ins, ucfirst operates on $_ by default). In foreach loops, when you modify the variable that holds the current element, this modifies the array. As the docs say, this is considered a feature!

From your confusion about @friends and $friends, you've shown that you haven't really learnt Perl in the best way (no offense intended). The difference between @friends and $friends in Perl is pretty fundamental, so it's important that you can understand it. I'd buy one of the books mentioned at the learn Perl site, and work through it. Don't worry, your investment in Perl will pay back very quickly!

Edit: fixed typo - changed uc to ucfirst


In reply to Re: making first letter of all words in array upper case by SuperCruncher
in thread 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.