In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/498b759bd12b378c541fc401200803b8c88c4a9b?hp=481c819bd64f89ed8dda98ea487aa03b1308b11d>
- Log ----------------------------------------------------------------- commit 498b759bd12b378c541fc401200803b8c88c4a9b Author: Ricardo Signes <[email protected]> Date: Fri Oct 4 10:42:49 2013 -0400 perlfunc: replace splice example with simpler one based on suggestions from Nicholas Clark and David Golden on perl5-porters ----------------------------------------------------------------------- Summary of changes: pod/perlfunc.pod | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 80dc367..3783564 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -6831,18 +6831,20 @@ The following equivalences hold (assuming C<< $#a >= $i >> ) unshift(@a,$x,$y) splice(@a,0,0,$x,$y) $a[$i] = $y splice(@a,$i,1,$y) -Example, assuming array lengths are passed before arrays: - - sub aeq { # compare two list values - my(@a) = splice(@_,0,shift); - my(@b) = splice(@_,0,shift); - return 0 unless @a == @b; # same len? - while (@a) { - return 0 if pop(@a) ne pop(@b); - } - return 1; +C<splice> can be used, for example, to implement n-ary queue processing: + + sub nary_print { + my $n = shift; + while (my @next_n = splice @_, 0, $n) { + say join q{ -- }, @next_n; + } } - if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... } + + nary_print(3, qw(a b c d e f g h)); + # prints: + # a -- b -- c + # d -- e -- f + # g -- h Starting with Perl 5.14, C<splice> can take scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced -- Perl5 Master Repository
