Updated April 1, 2023
Introduction to Perl pop array
The Perl pop array is the array method to remove the last element of the array list. The Perl function is to modify the Perl array list and return removed elements in the array list. The array is helpful for withdraw the last value of the Perl array list and return to the output screen. The pop array returns the last array element as an argument and takes it out from the array list. The array is passing and eliminates the last value, which is the must be an array list, not a simple list.
Syntax
- The Perl pop array syntax is below.
@Perl_pop_array = pop(@Array_list);
- Return the Perl pop array value syntax is below.
print " Perl pop array value is @Perl_pop_array " ;
Description:
- @Array_list is the variable of the initial Perl array with the value.
- @Perl_pop_array is the variable for the pop array function with the pop() method.
- The pop(@Array_list) is the method to work the pop array function in the Perl array.
- The array is the return of the last element of the array list using the print keyword and poped array variable.
How does the pop array 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.
Step 1:
Create a file with the .pl extension and save the file in the required command line path.
Example:
helloo.pl or first pearl.pl
Step 2:
Create the initial array variable and initialize with the required array list.
@prl_intial_ary = ('learning', 'Perl', 'technology', 'with', 'me');
Step 3:
Make an array variable and use the pop array method to remove the last element in the array list.
@prl_pop_ary = pop (@prl_intial_ary );
Step 4:
Return the array value in the output screen.
print "Perl poped array element is here: @prl_pop_ary \n ";
Combine all the above step to create a Perl pop array.
File name: my_perl.pl
@prl_intial_ary = ('learning', 'Perl', 'technology', 'with', 'me');
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
Examples
Here are the following examples mention below
Example #1
The array with string array list example and output.
@prl_intial_ary = ('learning', 'Perl', 'technology', 'with', 'me');
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
print "array element is here: @prl_intial_ary \n ";
Output:
Description:
- The Perl array list creates variables and initial with string values.
- The array variable creates and uses the pop method to remove the last element of the array list.
- The array returns the popped string elements using the print keyword.
Example #2
The Perl pop array with string array list example and output.
Code:
@prl_intial_ary = ('42', '129', '54', '79', '136');
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
print "array element is here: @prl_intial_ary \n ";
Output:
Description:
- The Perl array list creates variables and initial with numerical values.
- The Array variable creates and uses the pop method to remove the last numerical element of the array list.
- The array returns the popped numerical elements using the print keyword.
Example #3
The array in the array list example and output.
Code:
@prl_intial_ary = ('42', 'perl', '54', 'technology', '136');
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
print "array element is here: @prl_intial_ary \n ";
Output:
Description:
- The Perl array list creates variables and initials with string and numerical values.
- The array variable creates and uses the pop method to remove the last element of the array list.
- The array returns the popped elements using the print keyword.
Example #4
The Perl pop array with the last element in the array list example and output.
Code:
@prl_intial_ary = ('perl', 'technology');
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
print "array element is here: @prl_intial_ary \n ";
Output:
Description:
- The empty array list not returns any value and is undefined for the pop method.
- The initial array becomes null after popping the last element in the array list.
Example #5
The array with counting elements in the array list example and output.
Code:
@prl_intial_ary = ('learning', 'Perl', 'technology', 'with', 'me');
$pop_ary = scalar @prl_intial_ary;
print "initial array element value $pop_ary \n";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
@prl_pop_ary = pop (@prl_intial_ary );
print "Perl poped array element is here: @prl_pop_ary \n ";
print "array element is here: @prl_intial_ary \n ";
$pop_ary = scalar @prl_intial_ary;
print "perl popped array element value $pop_ary \n";
Output:
Description:
- The Perl initial array has five elements in the array list.
- Three elements remain in the array list after the working popping method.
- The pop method is used two times for the last two elements removed in the array list.
Conclusion
- The array is useful for modified the array elements in the array list.
- This method helps the array list to eliminate the last elements.
- The array method returns the last removable value on the output screen.
Recommended Articles
This is a guide to the Perl pop array. Here we discuss how the pop array function works in Perl and Examples along with the codes and outputs. You may also look at the following articles to learn more –