Perl | shift() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report shift() function in Perl returns the first value in an array, removing it and shifting the elements of the array list to the left by one. Shift operation removes the value like pop but is taken from the start of the array instead of the end as in pop. This function returns undef if the array is empty otherwise returns the first element of the array. Syntax: shift(Array) Returns: -1 if array is Empty otherwise first element of the array Example 1: Perl #!/usr/bin/perl -w # Defining Array to be shifted @array1 = ("Geeks", "For", "Geeks"); # Original Array print "Original Array: @array1\n"; # Performing the shift operation $shifted_element = shift(@array1); # Printing the shifted element print "Shifted element: $shifted_element\n"; # Updated Array print "Updated Array: @array1"; Output: Original Array: Geeks For Geeks Shifted element: Geeks Updated Array: For Geeks Example 2: perl #!/usr/bin/perl -w # Program to move first element # of an array to the end # Defining Array to be shifted @array1 = ("Geeks", "For", "Geeks"); # Original Array print "Original Array: @array1\n"; # Performing the shift operation $shifted_element = shift(@array1); # Placing First element in the end @array1[3] = $shifted_element; # Updated Array print "Updated Array: @array1"; Output: Original Array: Geeks For Geeks Updated Array: For Geeks Geeks Comment More infoAdvertise with us Next Article Perl | log() Function C Code_Mech Follow Improve Article Tags : Perl Perl-function Perl-Array-Functions Similar Reads Perl | unshift() Function unshift() function in Perl places the given list of elements at the beginning of an array. Thereby shifting all the values in the array by right. Multiple values can be unshift using this operation. This function returns the number of new elements in an array. Syntax: unshift(Array, List)Returns: Nu 2 min read Perl | rindex() Function rindex() function in Perl operates similar to index() function, except it returns the position of the last occurrence of the substring (or pattern) in the string (or text). If the position is specified, returns the last occurrence at or before that position. Syntax: # Searches pat in text from given 2 min read Perl | Useful String functions A string in Perl is a scalar variable and start with a ($) sign and it can contain alphabets, numbers, special characters. The string can consist of a single word, a group of words or a multi-line paragraph. The String is defined by the user within a single quote (â) or double quote (â). Perl provid 3 min read Perl | log() Function log() function in Perl returns the natural logarithm of value passed to it. Returns $_ if called without passing a value. log() function can be used to find the log of any base by using the formula: Syntax: log(value) Parameter: value: Number of which log is to be calculated Returns: Floating point 2 min read Perl | atan2() Function This function is used to calculate arctangent of Y/X in the range -PI to PI. Syntax: atan2(Y, X) Parameters: Y and X which are axis values Returns: Function returns arctangent of Y/X in the range -PI to PI. Example1: Perl #!/usr/bin/perl # Assigning values to X and y $Y = 45; $X = 70; # Calling atan 1 min read Perl | List Functions A list in Perl is a collection of scalar values. We can access the elements of a list using indexes. Index starts with 0 (0th index refers to the first element of the list). We use parenthesis and comma operators to construct a list. In Perl, scalar variables start with a $ symbol whereas list varia 4 min read Like