$STRING = join(JOINER, @LIST);
Perl's
join() function is used to connect all the elements of a specific list or array into a single string with the
JOINER expression. The list is
concatenated into one string with the element contained in the
JOINER variable in between each item.
@myNames = ('Jacob', 'Michael', 'Joshua', 'Matthew');
$someNames = join(', ', @myNames);
Think of the
@myNames array as a row of numbered boxes, each with a name in it. The
join() function would take all of the content in those boxes in the
@myNames array and connect them together with a comma and a space. The value of
@someNames then becomes "
Jacob, Michael, Joshua, Matthew". The list of names is
concatenated, or joined, by commas.