Updated April 12, 2023
Introduction to Perl join
The Perl join is one of the functions that can be used for joining the elements in the list. It can be converted into string data types. The converted data type value of the string is the single one and also it will need for using the expression in the string elements. It has also been parallelly and its opposite concept of the string split functions. the expression is used for any side of the position in the join method based on that the list values are joined each other and it formed into the single output of the script.
Syntax:
The Perl join is one of the built-in functions that can be used to joining the multiple user input values to joining the single variable value. It has its own syntax and attributes of the elements based on the list elements the user-inputs may be triggered into the single string values in the script.
#!/usr/bin/perl
$var = join(Expr, List);
Expr is any type of expression like the operators +, -, /, \, etc based on these expressions the input values are segregated from each other. The List is any input values it may be the string, integer, or numeric data types.
–some Perl script code logics—
How does join Function works in Perl?
The join() function of the Perl is used to joining the n number of elements in the single value. it may be any data types like string, number or integers, etc. The split and join function have some differences the regular expression takes the space for splitting the user input values by using some de-limiters concepts. For each set of values that is strings are split accordingly to each other likewise the join(,) method is the opposite direction of the split() function. It will take n number of user input values it may be the string or integer number types are joined together with using the same delimiters concept. By using join() method it first split the string values with some set of elements or list in the variable and afterward it will need to join each set of string values in the single variable string. If suppose when the user input values are sometimes no values in the list that time-space is been calculated by using “\s” it matches only the single whitespace characters in the element list. In some strings, the value spaces will be more when we use the split method the default single whitespace is calculated by using the delimiters but due to the empty string values of the list, the whitespace is to be doubled so the next value is to be pointed on the list. It will include the user input as preceding whitespaces because the user input values sometimes the lengthy word is split according to their meaning so it automatically takes the whitespace of that time in-fact the empty or null values of the strings will return the list of string values as the return type so based on the delimiters that are when we use more number of delimiters operators are used in the string it will be more specified and flexible to the empty string creation. So that list will be occupied more spaces in the memory so it’s to be avoided because they lack of performance issue is occurred while executing the script on that time.
While the string values are concatenated with each other it is a more efficient way for lengthy string values based on the user inputs by using some operators like ‘-‘ it will be used to split with each character and using the join function it will be joined each other. It’s a perlish type of function so it should be accepted for joining on the actual set of lists. It will not be supposed to the array holding list values because it pulls some humilities for each set of words in the strings as the list. When we use null as the value in the delimiter expression its nothing between the single(‘) or double(“) quotes of the values. So the regular expressions as the main role for splitting and joining the elements in the perl scripts.
Examples
Let us discuss examples of Perl join.
Example #1
Code:
#!/usr/bin/perl
$val = join( "-", "Welcome", "To", "My", "Domain" );
print"Welcome User please find your joined strings $val\n";
$val1 = join( "", "Welcome", "To", "My", "Domain" );
print"Welcome User please find your joined strings $val1\n";
$val2 = join( "~", "Welcome", "To", "My", "Domain" );
print"Welcome User please find your joined strings $val2\n";
$val3 = join( "***", "Welcome", "To", "My", "Domain");
print"Welcome User please find your joined strings $val3\n";
$val4 = join( "/", "Welcome", "To", "My", "Domain" );
print"Welcome User please find your joined strings $val4\n";
$val5 = join( "//", "Welcome", "To", "My", "Domain");
print"Welcome User please find your joined strings $val5\n";
Output:
Example #2
Code:
use strict;
use warnings;
use v5.10;
my @var1 = ('siva', 'raman', 'sivaraman', 'jhdvf', 'dfhj', 'jhgf', 'ywuewfy', '874', '9823874', 'jdh', '823', '897237knj', '84fn', '93', 'eiyru87');
my $vr2 = join ':', @var1;
say $vr2;
my $vr3 = join "-", $vr2, "values in teh list";
say $vr3;
$vr2 = join '', @var1, 'Welcome';
say $vr2;
Output:
Example #3
Code:
my $var = 'Welcome 8q6 jgasdjh 789899 jsadhbj** 99** *** uas 8987b87898 jgasvh 23 fd223 23 37 73 jh 9889 jj 998 0 () 7 s y8< >84 99jhhj', 'To my domain';
exit unless $var =~ /(o)/;
my @var1 = $var =~ //;
warn join('=', @var1), "\n";
exit unless $var =~ /(o)/;
my @var2 = split( //, $var );
warn join('-', @var2), "\n";
Output:
The above examples we used join function in different areas by using empty delimiters and using some valuable delimiters the script will be executed according to that and it displays the output.
Conclusion
In join() function or operator which performs the reverse operation against the split function because the join is concatenated with the other input values. By using the regular expression we first split the length input values and using the join() function to concatenated with each other.
Recommended Articles
This is a guide to Perl join. Here we discuss the definition and How does join function works in Perl along with examples. You may also have a look at the following articles to learn more –