You don't show us what output you get, and what output you expect, so it's somewhat hard to give you concrete advice. If you post an example and tell us where you think it goes wrong, that makes it much easier for us to address your actual misunderstandings.

join takes a list, so you don't need a for loop to build up the string from @nfirst.

If you call join with only one parameter, it will not prepend or append a space, so this line makes little sense:

$newfirst .= join(" ",(ucfirst $nfirst[$i]) );

A good approach here would be to first convert all first names to ucfirst using map:

@nfirst = map { ucfirst $_ } @nfirst;

... then you can use join directly:

my $NewFirst = join " ", @nfirst;

You can also do this in one go:

my $NewFirst = join " ", map { ucfirst $_ }, split /\s+/, $first ;

In reply to Re: trying to use join in a loop by Corion
in thread trying to use join in a loop by lamasculo

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.