start page | rating of books | rating of authors | reviews | copyrights

Programming Perl

Programming PerlSearch this book
Previous: 3.2.111 printf Chapter 3
Functions
Next: 3.2.113 q/STRING/
 

3.2.112 push

push 

ARRAY

, 

LIST

This function treats ARRAY as a stack, and pushes the values of LIST onto the end of ARRAY . The length of ARRAY increases by the length of LIST . The function returns this new length. The push function has the same effect as:

foreach $value (

LIST

) {     $ARRAY[++$#ARRAY] = $value; }

or:

splice @ARRAY, @ARRAY, 0, 

LIST

;

but is more efficient (for both you and your computer). You can use push in combination with shift to make a fairly time-efficient shift register or queue:

for (;;) {     push @ARRAY, shift @ARRAY;     ... }

See also pop and unshift .


Previous: 3.2.111 printf Programming Perl Next: 3.2.113 q/STRING/
3.2.111 printf Book Index 3.2.113 q/STRING/