Wednesday, August 18, 2010

The shift and unshift operators

The shift and unshift operators perform the operations on the start of the array ( the left side of an array or the portion with the lowest subscripts ).

shift Operator:

@array=qw # abc def ghi #;
$element_1=shift(@array); #gets abc
$element_2=shift @array; #gets def

unshift Operator:


unshift (@array, zyx); # @array has zyx abc
unshift @array, wvu; # @array has wvu zyx abd
@other_array=1..5; # has 1 2 3 4 5
unshift @array, @other_array; #@array now has 1 2 3 4 5 wvu zyx abd

No comments:

Post a Comment