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