| 1 | package List::EachCons; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | our $VERSION = '0.01'; | |||||||||
| 9 | |||||||||||
| 10 | 3 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||
| 11 | each_cons | ||||||||||
| 12 | ) ] ); | ||||||||||
| 13 | |||||||||||
| 14 | 3 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||
| 15 | |||||||||||
| 16 | 3 | our @EXPORT = qw( | |||||||||
| 17 | each_cons | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub each_cons($\@&) { | ||||||||
|
Subroutine
each_cons: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||
| 21 | 1 | my ($count, $list, $code) = @_; | |||||||||
| 22 | 1 | ▶ | return unless @$list >= $count; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | ▶ | return unless $count > 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 1 | my $ix = 0; | |||||||||
| 25 | 1 | my @current; | |||||||||
| 26 | 1 | push @current, $list->[$ix++] for 1 .. $count; | |||||||||
| 27 | 1 | my @result; | |||||||||
| 28 | 1 | while (1) { | |||||||||
| 29 | 2 | my $value = $code->(@current); | |||||||||
| 30 | 2 | ▶ | push @result, $value if wantarray; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 2 | ▶ | last if $ix >= @$list; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 1 | shift @current; | |||||||||
| 33 | 1 | push @current, $list->[$ix++]; | |||||||||
| 34 | } | ||||||||||
| 35 | 1 | @result; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 3 | 1; | |||||||||
| 39 | |||||||||||
| 40 | __END__ | ||||||||||