Perl join Function

Advertisements


Description

This function combines the elements of LIST into a single string using the value of EXPR to separate each element. It is effectively the opposite of split.

Note that EXPR is only interpolated between pairs of elements in LIST; it will not be placed either before the first or after the last element in the string. To join together strings without a separator, supply an empty string rather than undef.

Syntax

Following is the simple syntax for this function:

join EXPR, LIST

Return Value

This function returns the joined string.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

$string = join( "-", "one", "two", "three" );
print"Joined String is $string\n";

$string = join( "", "one", "two", "three" );
print"Joined String is $string\n";

When above code is executed, it produced following result

Joined String is one-two-three
Joined String is onetwothree


Advertisements
Advertisements