join takes two parameters, the 1st being a deliminator, and the next is a list of items to be joined together, using the deliminator as the glue

So...

@array = qw(one two three); $p_str=join ",",@array;
would set $p_str to one,two,three

But, your sample code has an extra little something... the list of items is ('?')x@array.

The x after a string ('?' in this case) is an operator that says, repeat this string x number of times, where x is the number following it.

So what is x? It is @array, and since this is in scalar context (Perl knows that it is supposed to supply a number not a list), @array returns the number of elements within the array.

so...

@array = qw(one two three); $p_str = '?'x@array;
sets $p_str to '???'

Finally,

@array = qw(one two three); $p_str = join ",",'?'x@array;
is equivalent to...
@array = qw(one two three); $p_str = join ",","???";
which simply joins the items ??? (note that there is only one item) together with commas.

Since there is only one item, there is no comma, and the final result is:

???

In reply to Re: Code Explanation by Sandy
in thread Code Explanation by Anonymous Monk

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.