in reply to Code Explanation

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:

???

Replies are listed 'Best First'.
Re^2: Code Explanation
by nedals (Deacon) on Jan 03, 2005 at 22:51 UTC
    A minor correction...
    @array = qw(one two three); $p_str = join ',',('?')x@array; ## parens added here puts the '?'s int +o list format
    The join will return the '?' seperated by commas. "?,?,?"
    In the post that you took this from, the '?'s are used as placeholders
Re^2: Code Explanation
by Errto (Vicar) on Jan 04, 2005 at 01:57 UTC
    $p_str = join ",",'?'x@array;

    Sandy's explanation is almost correct. The problem is that in the OP, there are parentheses around the '?' string. Those parentheses matter, because they cause the x operator to act on a list instead of a scalar. So actually, it's more like

    my @array = qw(a b c); my @tmp = ('?') x @array; # @tmp now contains ('?', '?', '?') my $p_str = join ",", @tmp; # $p_str now contains '?,?,?'