Definition of Perl Unshift
- The Perl unshift function is working opposite of the shift function in the Perl technology for array operation.
- The Perlunshift function is useful for shifting the array elements in the right direction.
- The Perlunshift function is adding a new array element on the left side and old elements shifting on the right side.
- The Perl unshift function is useful for a list of array shifting and adding new elements on the left side of the array list.
Syntax:
The Perlunshift function syntax is below.
Perl unshiftsyntax :unshift(@old_array_list, ‘new array elements’);
The Perlunshift() method is used for shifting the old array list toward the right direction and adding a new array list. The old array list variable is placed inside of Perl unshift method then-new array elements adding with the old array variable. The new elements of the string array placed inside of the single quotes (‘element of the array’) sign.
How does the Unshift Function Work in Perl?
- The download and install the Perl latest version in your operating system of the device.
https://www.Perl.org/ or http://strawberryPerl.com/ are mostly using the Perl IDE website link. - Create a file with the .pl extension and save the file in the required command line path.
Example: helloo.pl or first pearl.pl - Create the array variable and initialize with required array list.
@ary_vrbl = ('learning', 'Perl', 'technology');
- Print the Initial value of array list.
print "initial array list: @ary_vrbl \n";
- Use Perlunshift function for shifting array list and add required extra array elements.
unshift (@ary_vrbl, 'I', 'am') ;
- Print the array listafter using Perlunshiftfunction.
print "Array list using perlUnshift function : @ary_vrbl";
- Combine the working procedure and run on command line.
@ary_vrbl = ('learning', 'Perl', 'technology');
print "Initial array list: @ary_vrbl \n";
unshift(@ary_vrbl, 'I', 'am');
print "Array list using perlUnshiftfunction : @ary_vrbl"
Examples of Perl Unshift
Following are the examples are given below:
Example #1
The Perl unshift function with string array list example and output.
@ary_vrbl = ('C', 'Java', 'Php', 'Perl');
print "Basic language To Know Coder: @ary_vrbl \n";
unshift(@ary_vrbl, 'Paython', 'DotNet', 'Kotlin', 'Scala');
print "Advance language TO know Coder: @ary_vrbl \n";
unshift(@ary_vrbl, 'Bootstrap', 'Jquery', 'HTML', 'CSS');
print "Web Technology TO know Coder: @ary_vrbl \n";
Output:
Description:
- The array list creates variables and initial with string values.
- The array returns the only initial value which is the basic language to know coder.
- The first Perl unshift function return basic and advanced language to know coder in the array list.
- The second Perl unshift function returns basic and advanced language with web technology to know coder.
Example #2
The Perl unshift function with numerical array list example and output.
@ary_vrbl = (4, 5, 6, 7, 8, 9);
print "Basic value To Know user: @ary_vrbl \n";
unshift(@ary_vrbl, 1, 2, 3, 11);
print "Extra value TO know user: @ary_vrbl \n";
unshift(@ary_vrbl, 21, 32, 43, 54);
print "More value TO know user: @ary_vrbl \n";

4.5 (9,094 ratings)
View Course
Output:
Description:
- The array list creates variables and initial with numerical values.
- The array returns the only initial value which is basic values to know the user.
- The first Perl unshift function returns basic and extravalues to know the user in the array list.
- The second Perl unshift function returns basic and extra values with more values to know the user.
Example #3
The Perl unshift function in the array list example and output.
@ary_vrbl = ( 14, 'Perl', 'Python', 7, 8);
print "Basic value To Know user: @ary_vrbl \n";
unshift(@ary_vrbl, 1,'Java', 34);
print "Extra value TO know user: @ary_vrbl \n";
unshift(@ary_vrbl, 'Perl', 27, 'Bootstrap');
print "More value TO know user: @ary_vrbl \n";
Output:
Description:
- The array list creates variables and initial with numerical and string values.
- The array returns basic values to know the user which are numbers, Perl, and python language.
- The first Perl unshift function return basic and extra values to know the user in the array list which is numbers and java.
- The second Perl unshift function returns more values to know the user which are old and new array elements.
Example #4
The Perl unshift function in the array list with counting elements of array example and output.
@ary_vrbl = ('C', 'Java', 'Php', 'Perl');
print " Basic language To Know Coder: @ary_vrbl \n " ;
print "number of elements in the array list : ", unshift (@ary_vrbl, 'Paython', 'DotNet', 'Kotlin', 'Scala');
print "\n Advance language TO know Coder : @ary_vrbl \n " ;
print "number of elements in the array list : ", unshift (@ary_vrbl, 'Bootstrap', 'Jquery', 'HTML', 'CSS');
print "\n Web Technology TO know Coder: @ary_vrbl \n " ;
Output:
Description:
- The array list creates variables and initial with string values.
- The array returns the only initial value which is the basic language to know coder.
- The first Perl unshift function return basic and advanced language to know coder in the array list.
- The firstPerlunshift array has 8 elements in the array list.
- The second Perl unshift function returns basic and advanced language with web technology to know coder.
- The secondPerl unshift array has twelve elements in the array list.
Example #5
The basic Perl unshift function in the array list example and output.
@ary_vrbl = ('learning', 'Perl', 'technology');
print "Initial array list: @ary_vrbl \n " ;
print "Elements in the array list :", unshift(@ary_vrbl, 'I', 'am');
print "\n Array list using perlUnshiftfunction : @ary_vrbl " ;
Output:
Conclusion
- The Perlunshift function is used for modify the array list and sort the collection of strings.
- The Perl unshift function make array list user friendly, organized, and adjustable.
- The Perl unshift function recreates the array list and adding new elements in the array.
Recommended Articles
This is a guide to Perl Unshift. Here we also discuss the definition and how does the unshift function work in perl? along with examples. You may also have a look at the following articles to learn more –