Home >> perlfunctions >>Perl function: shiftshift is taking the first element of an array (the leftmost part), while the opposite is pop which is taking the last element of array (the rightmost part).my @arr=("a","b",7,8,9);
my $x = shift @arr;
print "$x\n"; # a
print "@arr\n"; # b 7 8 9
guess what will shift @_ do?@_ contains the arguments passed to subroutine. shift will remove the first argument value from @_. An interesting thing suppose you run a perl file via command line and you are passing arguments... like.. $ ./myfile "arg1" "arg2" myfile is a perl file like.. #!/usr/bin/perl use strict; my $a1= shift; my $a2=shift; in above case $a1 will get "arg1" and $a2 will have "$arg2" Perl functions
|
List of all perl functions Perl function : split Perl function: abs Perl function: chomp Perl function: chop Perl function: chr Perl function: crypt Perl function: eval Perl function: hex Perl function: lc Perl function: lcfirst Perl function: length Perl function: oct Perl function: ord
|