Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL shift Function



Syntax

shift ( [ARRAY] )

shift


Definition and Usage

Returns the first value in an array, deleting it and shifting the elements of the array list to the left by one. If ARRAY is not specified, shifts the @_ array within a subroutine, or @ARGV otherwise. shift is essentially identical to pop, except values are taken from the start of the array instead of the end.

Return Value

  • undef if the array is empty

  • First element in the array

Example

Try out following example:

#!/usr/bin/perl

@array = (1..5);
while ($element = shift(@array)) {
    print("$element - ");
}
print("The End\n");

It will produces following result.

1 - 2 - 3 - 4 - 5 - The End


Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names