in reply to Code Explanation
So...
would set $p_str to one,two,three@array = qw(one two three); $p_str=join ",",@array;
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...
sets $p_str to '???'@array = qw(one two three); $p_str = '?'x@array;
Finally,
is equivalent to...@array = qw(one two three); $p_str = join ",",'?'x@array;
which simply joins the items ??? (note that there is only one item) together with commas.@array = qw(one two three); $p_str = join ",","???";
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 | |
|
Re^2: Code Explanation
by Errto (Vicar) on Jan 04, 2005 at 01:57 UTC |