February 2012
Intermediate to advanced
1184 pages
37h 17m
English
pushARRAY,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:
for my $value (listfunc()) {
$array[++$#array] = $value;
}or:
splice @array, @array, 0, listfunc();
but it 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.
Starting with v5.14, push can
take a reference to an unblessed array, which will be dereferenced
automatically. This aspect of push is
considered experimental. The exact behavior may change in a future
version of Perl.
Read now
Unlock full access